Picon

Many rules for reusability and testability



I have problem similar to this where I need to decide how to deal numerous rules.


I own 10 houses. There are 10 renters. At the end of the month, I check whether all the 10 renters have paid their rent. If they have not paid their rent, I have to send an eviction notice. There are many rules to be checked before sending the eviction notice.


1. Have I sent a reminder to the renter to pay the rent before the end of the month?

2. Have I given the renter a grace period of 5 days after the reminder was sent?

3. Whether or not the renter has his furniture in the house? If he does not have, send the eviction notice immediately else send a warning notification with 10 days grace period.

4. Is the renter living in the house for more than 5 years? If so, send a warning notification with a 30 days grace period to pay the rent.

5. ...


I can think of two entities here OWNER and RENTER. I can also think about


Owner owner = new Owner();

Renter renter = new Renter();

if (owner.Evict(renter))

{

// Let the UI know the renter has been evicted after checking all the rules.

}

else

{

// Let the UI know the renter h as not been evicted because certain rules failed like the renter has not been sent // a reminder.

}


There can be numerous rules to meet the Evict behavior. They are agile, so it can change during the development. They also need to be tested.


When I looked at some DDD examples, I see that the rules like these are baked into the Evict method. Adding a new rule requires the module that holds he Evict method need to be compiled. I would rather test HasRenterBeenSentAReminder rather than a Evict method.


What pattern I can follow to implement a kind of Business Rules Engine in DDD?


Thanks.




__._,_.___
Posted by: varghese.pallathu <at> yahoo.com



__,_._,___
Picon

Conceptual Vs Data Vs Domain model



I'm trying to change the mindset of my data model design to design a Catalog, Products and Category domain model.


The conceptual model: 


Catalog contains Products belonging to a Category.


Data Model:


Table Catalog

[

CatalogID

]


Table Product

[

CatalogID (Catalog.CatalogID Foreign Key)

Categ oryID (Category.CategoryID Foreign Key)

]


Table Category

[

CategoryID

]


Domain Model:


The domain model (class model) can be modeled in two ways as following. Thinking about the aggregate root, the Catalog can be an aggregate root.


To me the Model 1 resembles a data model when the Model 2 resembles an aggregate root.


What do you think?


Model 1: 


class Catalog

{

List<Product> Products;

}


class Product

{

Category Category;

}


class Category

{

}


Model 2:


class Catalog

{

List<Category> Categories;

}


class Category

{

List<Product> products;

}


class Product

{

}




__._,_.___
Posted by: varghese.pallathu <at> yahoo.com



__,_._,___
Picon

Usability as core domain?



Hi,

Is it possible for e-commerce business (selling certain services related to event organizing) to have usability as a core domain? The business has few web based applications dealing with various areas of the business. From what I read about DDD most businesses have at some point a core domain (a part of business that brings most value and/or competitive advantage to that business).

It seems that business people want to focus on usability of one of their web based applications as a way for their business to distinguish itself from competitors. I just can't wrap my head how would that fit with DDD. I always pictured a core domain as one where you would make heavy use of tactical DDD patterns and other GoF design patterns. Usability as core domain doesn't fit that picture.

Thanks

  

 




__._,_.___
Posted by: "Stefan A." <acid24 <at> gmail.com>



__,_._,___
Picon

Expanding entity that is agile



I have an entity similar to Product. It has many properties/attributes like Name, Description, few different prices like Original Price, Sales Price, Discounted Price, Cost, Manufacturer etc... Counting all the properties of this Entity that I use, it has 20 properties. To be agile, I see that this Entity can grow by adding new properties.


I'm sure I'm not modelling this Entity properly. I should have all pricing properties as Value objects. And move some properties to a different entity. However, I'm anticipating more properties are added which can ultimately change the version of the Entity. To put this way "Embrace change".


Is there a pattern to make an Entity agile, so a compilation is not needed for the Entity when a property/containing object is added and thus no deployment of the existing Entity is needed?


Is using a Key/Value pairs for this Entity a good practice?


Or use the inheritance with a hierarchy like ProductBase, ProductInfo (derived from ProductBase), ProductSpec1 (derived from ProductInfo), ProductSpec2 (derived from ProductSpec1)? By following this pattern, when a new property is added, I can create a new class called ProductSpec3 and derive from ProductSpec2 and deploy through a new assembly or DLL and don't touch the existin g assemblies.


Thoughts?




__._,_.___
Posted by: varghese.pallathu <at> yahoo.com



__,_._,___
Picon

Aspects as a modelling bridge between OOD and SOA



While Object Oriented approaches are the option of choice for the design of software components, they may fall short when business domains are to be shared by changing applications across architectures. Such functional requirements are better served by services oriented architectures, and aspects oriented approaches may provide a modelling bridge between Object and Service oriented paradigms

Remy

https://caminao.wordpress.com/how-to-represent-objects-and-activities/abstractions/objects-aspects/



__._,_.___
Posted by: caminao <at> gmail.com



__,_._,___
Picon

Is IoC containers harmful for DDD?



I was reading Growing Object-Oriented Software book and came across this article Dependency Injection harmful by Nat Pryce.


I had hard time understanding what Nat is talking in that article. Is he talking about not using the word dependency injection or not using a IoC container to achieve the DI?


I have used Microsoft Unity and MEF before, and they are very convenient in building up the objects. MEF is extremely useful where the parts can be discovered automatically. For example, the core domain depends on pricing service which can be switched to any implementation thr ough Unity as well as MEF. With MEF, just dropping a dll is enough for the domain to pick up the new implementation. Without a IoC or MEF, it would require a lot of code to inject a dependency.






__._,_.___
Posted by: varghese.pallathu <at> yahoo.com



__,_._,___
Picon

Bounded Context with modules in .NET



As I understand, a Bounded Context can contain multiple modules.


Let us take a Product Catalog Bounded Context. This Product Catalog BC can contain modules like CatalogManagement, ProductManagement.


When it is implemented in .net, the CatalogManagement and ProductManagement can be implemented as assemblies. Since they are part of the same Bounded Context, should they be implemented in the same namespace to draw the boundary?


This is my understanding of Bounded Context. The core domain and sub domain are discussed at the problem space while Bounded Conte xt and Module are discussed at the solution space where there are implementations. I don't know how the Bounded Context and Modules are implemented in .NET.


Thanks.



__._,_.___
Posted by: varghese.pallathu <at> yahoo.com



__,_._,___
Picon

Transactionally Consistency in DDD



I'm stuck at a quote from  Vaughn Vernon in his IDDD book. Here it goes:


"An Aggregate is composed of either a single Entity (5) or a cluster of Entities and Value Objects (6) that must remain transactionally consistent throughout the Aggregate’s lifetime." - Implementing DDD by  Vaughn Vernon


I'm trying to understand "transactionally consistent" that is mentioned here. Is it the behavior of the repository that makes sure the aggregate should be consistent when it is read or committed from the database.


Or it the consistency of the aggregate when it is operated in memory and goes through state changes and shows consistent behavior.




__._,_.___
Posted by: varghese.pallathu <at> yahoo.com



__,_._,___
Picon

Aggregate or not?



I have an example to understand the aggregate design.


The business language goes this way. I own ten restaurants. I will buy furniture from a furniture store and use them in any of the five restaurants. I will hold, assign, remove or swap furniture in the five restaurants. When I buy a new furniture, I will ask the furniture store to hold the furniture in their warehouse until I decide which restaurant I should use that. Sometimes, I don't have time to decide which furniture should go which restaurant. I will hire an interior designer to look at the furniture on hold in the furniture warehouse to decide where they should be put.


Thinking about the composition, I can have a Restaurant entity  and a Furniture entity.


class Restaurant

{

private List<Furniture> Furnitures;


void BringSome(List<Furniture> furnitures);

void RemoveA(Furniture furniture);

}


class Furniture

{

Restaurant Restaurant;


void AssignMeTo(Restaurant restaurant);

void RemoveFrom(Restaurant restaurant)

}an>


The Restaurant is a good candidate for aggregate root. It contain the Furniture.


Can the Furniture be an aggregate root too? My interior designer need to have access to the Furniture which are on hold (still in the Furniture warehouse) and not assigned to any restaurant, so a furniture can exist without it's root, but it will become part of the root only after it is assigned. I'm comparing this to Order.OrderLineItems relation. An order line item can't exist without an order. But in my example, a furniture can exist without a restaurant.


Appreciate your thoughts.


n>






__._,_.___
Posted by: varghese.pallathu <at> yahoo.com



__,_._,___
Picon

Re: Massive stored proc data base operation to DDD



Hi Varghese,

If your behaviours cannot be defined as simple methods (or functions), I think you should simply reconsider your model.
Remember : your domain model should be designed to enable the creation of value (a.k.a. the implementation of methods or functions) of your application. It is using domain vocabulary (ubuquitous language) but its design and structure should be made to support the domain scenarios. In other words, you are not building a realistic model of the world but rather a model for a particular purpose (i.e. to support domain scenarios): modelling is driven by those scenarios.

In your particular case, you want to create two clusters of products ("Vegetable Products" and "Non Vegetable Products") from an "Unclassified Product Sets" (I think we have here three nice aggregate roots). "Unclassified Product Sets" might have a method "classify" (probably the entry point of your scenario) which takes a set of "Companies" (probably Value Objects) as a "vegetable Vendors" input argument, and a tuple of "Vegetable Products" and "Non Vegetable Products" as output argument.

It seems to me that this "classify" method can perfectly be implemented (directly on the class or as an "Unclassified Product Set Repository" method) in a stored proc and be perfectly OO (or FP if you prefer). Moreover this is definitely not an anemic model at all !

The problem you face comes from the fact you expressed it with the right words, but in the wrong Bounded Context.

Regards,

Greg Weinbach



__._,_.___
Posted by: =?UTF-8?Q?Gr=C3=A9gory_Weinbach?= <gweinbach <at> gmail.com>



__,_._,___
Picon

Massive stored proc data base operation to DDD



Lets take an example of a product classification. All the products needs to be classified as vegetable or not. This is a command which should take some time to complete because there are millions of products. This is a B2B scenario, so the agents do this operation quite often like few times every day. This is a UPDATE operation not a read operation. The business logic is, the product can be classified as vegetable if that product is from company A, B & C. If the product is not from those companies they are not vegetables. There are millions of products in the database with it's vendor. Approaching this from a data perspective, this can be done in a stored procedure with few lines of code. The operation may take only few seconds even if it is done synchronize.


Now let me approach this from a DDD perspective. As I understand, the DDD goes against the idea of putting the logic in the stored procedure. The logic can be put as a behavior on product which can self classify based on who is the source, or the aggregate root can do that job. To do this, all the million products need to be read into memory from the database, process and then save it back to the database through the repository (whether it is SQL, Document based, mySql or whatever).

 

The problem here is the large amount of memory this operation needs when done using the DDD approach. If the operation is done in chucks like 50,000 the repository has to first figure out how may products needs to be classified and&nbs p;the domain has to plan the long running operation in chunks. Surely, this approach is going to take more time and a bad user experience for the user who has to wait more time than a process than a stored procedure takes.


What is the reasonable approach to DDD when it comes to long running massive data processes? Is the delay expected, so the app has to inform the user that the classification is going to take time like 5 minutes or so and will let the user know when that is complete? And should not use stored procedure to have the classification logic, but have the business logic as part of the domain.


You can think about the classification business logic which can change in the future. In this example, it is b ased on the vendor who provides the product. That can change to country. For example, all the products come from Country A will be wine. There is a greater flexibility with having this logic as part of the domain. But what worries me is the large amount of memory this operation has to take.


Appreciate feedback from DDD gurus.





__._,_.___
Posted by: varghese.pallathu <at> yahoo.com



__,_._,___

Gmane