-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Environment is highly coupled with childs of EnvironmentObject #16
Comments
Actually, when I was working on this project, ChatGPT suggested using the Visitor pattern many times. However, I’m not really familiar with it. Is that possible to use UML to show what the changes would look like? |
Here is the uml to demonstrate the result of refactoring. the The Visitor pattern can do a lot more than just get. But I currently only use it on Getter. Other usage can be discussed in the future For the deadOrganism. I suggest we can add variable to Organism to indicate dead. Or is there a reason we need to store them in a different vector ? |
This approach decouples However, two points should be considered:
|
The Maybe we could add another discussion or refactor issue to talk about this. |
Another approach is to only use a getObject method that accept a filter
lambda function that get what the user want, such as id or class name.
we can make the EnvironmentObject constructor set a attribute string that
is equal to the class name.
This way, user can easily customize the filter without exposing too many
complex things. They just need to implement a simple boolean function. And
this can adapt to complex EnvironmentObject that has custom attribute
defined by users.
|
Can you provide some syntax for me to better understand what it will look like? |
I have redesign the getObject method that accept a custom filter which accept a This will not expose too much things to users. and it's quite common for python scripting like below.
|
potential recurrent problem: the
Environment
is coupled withFood
andOrganism
, which will limit the scalability if there are new child ofEnvironmentObject
orFood
,Organism
. That is, we need to add newgetFunction
or new map inEnvironment
.solution: I suggest we can apply visitor pattern so that we can add different getter without hard coding
FoodAllFoods
,getAllOrganism
. That is, we can define different getter and use it as parameter in the one and onlygetEnvironmentObject(getterFilter)
.Expected result: Environment only depend on
EnvironmentObject
The text was updated successfully, but these errors were encountered: