Correct OO match modeling

Something continues to appear in my programming, and it is that two things are the same from some point of view, but different from the others. For example, imagine that you are plotting a train station connected by rail, then the Vertex and RailStation classes are sometimes the same, and sometimes not.

So, imagine, I have a schedule that is very similar to railway stations and trains. Then I pass this graph to another object that removes some peaks, and then I want the corresponding train stations to disappear.

I do not want to do the “properties” of the rail stations of the peaks, this is not so. In addition, the problem is symmetrical: if I remove the rail, I want the corresponding vertex to disappear. What is the correct way to OO model or match. I am willing to go for a few extra miles by writing a few support methods or classes, if in the end the general use is simple and simple.

I am currently using the Smalltalk programming language, but the question, in my opinion, is not very small. I just mention this because in Smalltalk you can do cool tricks, like learning a call stack, which can be useful in this context.

Update : Well, RailStations are not Tops! They are?

, , . . , ? , . , , .

, → removeChild: ,

removeChild: aChild
    (parent relationshipWith: aChild) disband.

, , . . :

parent children removeAllSuchThat: [:e | e age < 12]

.

. , ? , , , . , , , ?

+3
5

? , ​​ Vertex?

" ". , . , , . , , , . , .

/, . , , / . OTOH, , , (, - ), / , .

+3

, , RailStation Vertex (is-a relationship). . smalltalk . , RailStations, , ( ) , .

, ( ).

+2

( ). " , ", , -, , , - .

, ? , , , , ?

, -- .

+2

"" - .

, " ?".

, , , , .

: , . "" " " , Person.

, Relationshiphp, , . Relationship, , , - . , ( ) , , - "" .

. , PeerRelationship ( FriendRelationship).

() (ren) .

, "" Person ( Vertex) , , , , , ( ) .

.

+1

, . http://www.squeaksource.com/Fame.html

We use a specialized subclass Collectionthat updates the opposite end when adding or removing elements. In addition, you can annotate your classes with pragmas to comment on relationships. These pragmas are used by the Fame frame to do all kinds of nice things.

+1
source

Source: https://habr.com/ru/post/1708873/


All Articles