PacktPublishing / Designing-Hexagonal-Architecture-with-Java

Designing Hexagonal Architecture with Java, published by Packt
MIT License
201 stars 119 forks source link

Issue in creating entities with multiple networks #30

Open slowtree opened 1 year ago

slowtree commented 1 year ago

https://github.com/PacktPublishing/Designing-Hexagonal-Architecture-with-Java/blob/8d702aea0db322fb2305fc5ae17043619abd868a/Chapter02/src/main/java/dev/davivieira/domain/entity/Switch.java#L26

ciao guys, I’m reading through the book but I think this method is not allowing me for creating Switch entities with multiple networks. Am I reading it wrong? thanks a lot, Paolo

P.s. On the book (page 41) the name of the private list attribute hosting the Network objects doesn’t match the “networks” member returned but the getNetworks method.

m4ndr4ck commented 1 year ago

@slowtree Hey! No, you are not reading it wrong. The logic, indeed, needs to be fixed. Something like the excerpt below would allow the creation of Switch entities with multiple networks:

public Switch addNetwork(Network network, Router router) {
        List<Network> networks = router.retrieveNetworks();
        networks.add(network);
        return new Switch(this.switchType, this.switchId, networks, this.address);
}