DDD Terminologies

Terminologies are always an important part of understanding any design pattern. Below are some of  the important terms that we come across on a daily basis if we are implementing our application in DDD way.

You can read more about DDD in our previous articles here.

 

Ubiquitous language: –

In DDD world, Its a language which is understood by every one. i.e. tech guys should talk in language which can be easily understood by business people and vice-versa, irrespective of their role in project, let it be testing team, product owner, project manager or scrum master or anyone. 

 

Entities: –

Entities are the classes that represents the domain concepts and have identity. This usually means that there is a unique identifier key associated with the entity.

 

Factories

Since an aggregate should always be in a consistent state it is important that they are constructed in a consistent state to the user. Factories provide a way to ensure that new instances of an aggregate always start in a consistent state.

 

Repositories

Repositories allow us to persist and retrieve aggregates without dealing directly with the underlying persistence layer. They store aggregates in a consistent manner. More specifically, it knows about the aggregate that it is returning. A repository returns an Entity (or collection of Entities) and the aggregate for which that Entity is the Aggregate Root.

 

Aggregate: –

An Aggregate is nothing but a group of Entities or Value Objects. Its nothing but a Class having another Classes(Entities or Value Objects) declared inside the Class or a Class that is treated as an unit for the purpose of data changes.

Example:

public class Student {
    private Name studentName;
    private Address address;
    private Standard standard;
    private Integer age; 
    …
}

We could have declared Student class with studentName as String, address as String or standard as String also. Doing so, we would be making a very generic class.

 

AggregateRoot: –

An aggregate will have one of its component objects be the aggregate root. Any references from outside the aggregate should only go to the aggregate root. The root can thus ensure the integrity of the aggregate as a whole.

You can consider above declared Student class as a whole an Aggregate and just Student its AggregateRoot. 

AggregateRoot

Bounded Context

Bounded context is something which changes the definition of something which had some other definition in some other context. Confused !! 🙂

Let’s say, you are an Employee of your company and you have EmpId. Your same EmpId will have different-2 context in different-2 company departments. On given to transport department, they will look for whether you are using any company transport or not. But the same EmpId given to finance team, they will look for your financial stats. They don’t care about whether you are using any company transport or not OR whether you have finished all your training on time or not but the HR does. So here, Departments are that bounded context. 

 

Command: –

Command is an operation that makes some change to the system or Command is something which changes the state of your data in your application. 

Say, you are placing your online order at Amazon. After successful placement of your order since you don’t get your product but you get confirmation of something like Order Successfully Placed. Amazon, behind the scene fire the command to the availability of that product and if found in their inventory they change the state of your order from Order Successfully Placed to Order Confirmed.  And after every successful execution of commands you will a different state of your order like Dispatched, Ready to Deliver, Delivered.

Events: –

Events are something which depicts “Something Happened“. Events are the way in domains to let the other domain know that something happened here and if you (other domains) are interested in them please update your self.

Say, you are placing your order at Amazon. Once successfully placed and confirmed, the Order domain will issue an event (i.e. OrderConfirmedEvent) to other domain know. The Shipment domain is the one who can listen to this event and perform necessary action. 

 

Hope this had cleared your doubts with above mentioned terms.

 

The list is not finished yet. I’ll be updating with few more soon…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s