mardi 25 janvier 2022

Design Pattern Help --each object can alter the state of the other?

I am new to design patterns so seeking guidance. I believe I should use an observer pattern but is this true if each observer can alter the state of the other?

Specifically, my situation is as follows: I have a numpy array of elements e.g. 10x10 array. I have a separate object that I plan to make a class - Object A. Each instance of object A connects to a subset of the 10x10array but importantly there can be overlap so at position 4, 3 in the array I might have concrete objects A, B, and E attached.
Now, during the course of the program there are rules which govern how many objects can be attached to 1 array element as well as requirements on the objects to attach to a certain number of array elements. As a result, concrete object A can alter the state of the array elements i.e. attach to different positions in the array, but depending on the array elements' other attached concrete objects this can affect how A connects. In other words, my attach objects need to "observe" the array and the array elements need to "observe" the attach objects. Should I use an observer design pattern or is there some other pattern I should be exploring?

Not sure if it matters but this will be a python implementation.

Aucun commentaire:

Enregistrer un commentaire