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

0 Answers0