2

From the answer to Must the use cases extend the entities in Clean Architecture? I have known that the use cases must NOT extend the entities. It's fine, but what do I have to do with the properties of entities which are depending on the application?

Very strictly speaking, these rules (note: the enterprise business rules) would make or save the business money, irrespective of whether they were implemented on a computer. They would make or save money even if they were executed manually.

The below entity is matching with this concept because each product has a title which could be written on the physical label and price:

class Product { public title: string; public price__dollars__withoutTax: number; public constructor(properties: Readonly<{ title: string; price__dollars__withoutTax: number; }>) { this.title = properties.title; this.price__dollars__withoutTax = properties.price__dollars__withoutTax; } } 

Unlike this, the below class has some fields which exist only inside the application - ID, createdAt__ISO86101, updatedAt__ISO86101

class Product { public readonly ID: number = Product.generateID(); public title: string; public price__dollars__withoutTax: number; public createdAt__ISO86101: string; public updatedAt__ISO86101?: string; public constructor(properties: Readonly<{ title: string; price__dollars__withoutTax: number; }>) { this.title = properties.title; this.price__dollars__withoutTax = properties.price__dollars__withoutTax; this.createdAt__ISO86101 = new Date().toISOString(); } private static counterForID_Generating = -1; private static generateID(): number { Product.counterForID_Generating++; return Product.counterForID_Generating; } } 

How the second version of Product class should be organized in the Clean Architecture hierarchy?

enter image description here

5
  • There is nothing inherently “implemented by a computer” about an Id or a time stamp. Commented Oct 11, 2022 at 10:31
  • 1
    Why createdAt__ISO86101 and updatedAt__ISO86101 are application specific? If Product as an entity of the domain is so abstract, then let it be so. Don't make it concrete. It can be just an "abstraction" too. By the way, there're other techniques to expand data models. One of them can be persisting additional data in different places. Another is via decorators and composition. Remember that the domain will not care how data is persisted or managed "out" of its scope. Commented Oct 11, 2022 at 11:26
  • @candied_orange, Why? ID is not the product code, just some token which being used for the searching, for example, or by frontend framework in iterative rendering. The timestamp is not the production data of the physical product, it just the registration date/time in the database. Commented Oct 12, 2022 at 8:48
  • @Laiv, because createdAt__ISO86101 is not the date/time of the production of physical product - it just the date of adding to digital database. The updatedAt__ISO86101 is the date/time of updating the data in digital database. "By the way, there're other techniques to expand data models." - thank you for the advise. Sounds great, but have you some links with examples? Commented Oct 12, 2022 at 8:59
  • 1
    The criteria you gave was: “They would make or save money even if they were executed manually.” you can set and keep time stamps and IDs manually. Ask an old librarian what index cards were originally used for. Commented Oct 12, 2022 at 12:37

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.