官术网_书友最值得收藏!

Entity implementation

For the first interface, you could have an abstract class or interface that is required by all the entities. For example, if we consider ID and name, attributes would be common for all entities.

Therefore, you could use the abstract Entity class as an abstraction of the entity in your domain layer:

public abstract class Entity<T> {  
    T id; 
    String name; 
    ... (getter/setter and other relevant code)
}

The following diagram contains the OTRS domain entities and their relationships:

Domain entities

Based on that, you can also have another abstract class that inherits Entity, an abstract class:

public abstract class BaseEntity<T> extends Entity<T> { 
 
    private final boolean isModified;

public BaseEntity(T id, String name) { super.id = id; super.name = name; isModified = false; } ... (getter/setter and other relevant code) }

Based on the preceding abstractions, we could create the Restaurant entity for restaurant management.

Now, since we are developing a table-reservation system, Table is another important entity in terms of the domain model. So, if we follow the aggregate pattern, Restaurant would work as a root, and the Table entity would be internal to the Restaurant entity. Therefore, the Table entity would always be accessible using the Restaurant entity.

You can create the Table entity using the following implementation, and you can add attributes as you wish. For demonstration purposes only, basic attributes are used:

public class Table extends BaseEntity<BigInteger> { 
 
    private int capacity; 
 
    public Table(String name, BigInteger id, int capacity) { 
        super(id, name); 
        this.capacity = capacity; 
    } 
 
    public void setCapacity(int capacity) { 
        this.capacity = capacity; 
    } 
 
    public int getCapacity() { 
        return capacity; 
    } 
} 

Now, we can implement the aggregator Restaurant class, shown as follows. Here, only basic attributes are used. You could add as many as you want, and you may also add other features:

public class Restaurant extends BaseEntity<String> { 
 
    private List<Table> tables = new ArrayList<>();
public Restaurant(String name, String id, List<Table> tables) { super(id, name); this.tables = tables; } public void setTables(List<Table> tables) { this.tables = tables; } public List<Table> getTables() { return tables; } @Override public String toString() { return new StringBuilder("{id: ").append(id).append(", name: ") .append(name).append(", tables: ").append(tables).append("}").toString(); } }
主站蜘蛛池模板: 嘉义市| 沅陵县| 沭阳县| 海淀区| 岑巩县| 博客| 云南省| 错那县| 伊宁市| 花莲市| 扶风县| 陆良县| 开原市| 顺平县| 新和县| 丹寨县| 桂东县| 潍坊市| 察哈| 金塔县| 湾仔区| 甘德县| 客服| 湟源县| 伊宁县| 山阴县| 大渡口区| 广宁县| 龙陵县| 上饶市| 清水河县| 肇庆市| 仲巴县| 铁岭市| 确山县| 巴塘县| 西乌珠穆沁旗| 鄂尔多斯市| 深州市| 拜城县| 吉木乃县|