Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What I think you have found in your pretty nice example and explanation is that OO does not solve all problems well. As long as the responsibility is well shaped and sharp, everything is fine. And as long each responsibility fits in exactly one bucket (the class), it is pretty easy to design. But here you have a tradeoff:</p> <ul> <li>If I define for each responsibility a separate class, I will get a bloated design that is pretty difficult to understand (and sometimes to maintain).</li> <li>If I include for each separate responsibility at least one interface, I will get more classes and interfaces than I need.</li> <li>If I decide that one of the two classes is responsible for the relation as well, this one object has more knowledge than usual about the other.</li> <li>And if you introduce in each case a mediator or something similar, your design will be more complex than the problem.</li> </ul> <p>So perhaps you should ask the questions:</p> <ul> <li>What is the likelihood that the relation between the 2 objects will change?</li> <li>What is the likelihood that the relation will exist between more 1 type of objects at each end?</li> <li>Is that part of the system a highly visible part, so that a lot of other parts will interface it (and therefore will be dependent on it)?</li> </ul> <p>Take the simplest solution that could possibly work and start with that. As long as the solution is kept simple, it is only your code (you don't design a library for others), there are chances that you can change the design later without hassle.</p> <p>So in your concrete case, </p> <ol> <li>the board field should have access to the whole board XOR</li> <li>the figure on the field should have the responsibility of moving XOR</li> <li>there should be an object type (ChessGame?) that is responsible for the overall knowledge about moving, blocking, attacking ...</li> </ol> <p>I do think that all are valid, and it depends on your special "business case" which one is the most valid.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload