Skip to content
On this page

Criteria

Intent

Coming soon...

Problem 😢

Coming soon...

Solution 😋

Coming soon...

Real-World Analogy 🌍

Coming soon...

Structure

Coming soon...

Code example

When creating our repositories we may want to fetch our resources filtering by some of their attributes. Thats why is easy to come out with code that resembles this:

ts
import { User } from "./User";

export interface UserRepository {
	create(user: User): Promise<void>;
	findAll(): Promise<User[]>;
	findById(id: string): Promise<User>;
	findByAge(age: number): Promise<User[]>;
	findByName(name: string): Promise<User[]>;
	findByAgeAndName(age: number, name: string): Promise<User>;
	findByOccupation(occupation: ""): Promise<User[]>;
	// findBy...
}
1
2
3
4
5
6
7
8
9
10
11
12
.
├─ shared/
│   ├─ application
│   ├─ domain
│   │   └─ Criteria.ts
│   └─ infrastructure/
└─ user/
    ├─ application/
    ├─ domain/
    │   └─ UserRepository.ts
    └─ infrastructure/
        └─ MongoUserRepository.ts
1
2
3
4
5
6
7
8
9
10
11
12

Applicability

Coming soon...

How to Implement

Coming soon...

Pros and Cons

Coming soon...

Relations with Other Patterns

Coming soon...