So we have been given an assignment in Java(that is design pattern heaven right?
), and we have been making a "game" on top of framework that was wrote by the school, maybe not(this doesnt matter in the slightest).
A bit of background: Anything that can be shown on screen(has animation etc) is called Actor. There is AbstractActor that we wrote that has certain functionalities added on top of the Actor(actor has been provided as interface).
Important note: the Actor has method act, which is called by the library every frame on all actors present in the world.
The assignment has another part tho, that is, we have to create 10 Actors by ourselfs that are somewhat unique in their behaviour compared to what we did in the class.
That isnt much of a problem, the kicker is this:
We have to make use of:
1. State pattern
2. Observer pattern
3. Decorator pattern
4. Some behavioral patter of our choice except Null Object, Template Method and Iterator.
The first two are easy because they are also very self explanatory. However I have hard time getting the grip on the third, and coming up with something that could satisfy some behavioral pattern.
I thought of using Memento(as a Quick save/load functionality) but you may see that Srategy could also be used.(Command pattern is used somewhat in the assignment, so I can say I used that too)
I dont mind coding anything, and Im not asking for "do it for me", I just want a nudge or a confirmation of sorts, of whether the following can be considered Decorator pattern, or alternativelly Srategy, or some mix.
According to what I digged from wikia and from https://sourcemaking.com/design_patterns/behavioral_patterns I came up with following possible scenarios:
- I will have at least 2 enemies. One will try to chase you and when he touches you he deals damage. The other one will most likely be stationary but he will be looking at you and firing poisonous missiles at you(the poison and the missile are already coded).
If I made some barebone "framework" for the enemies which would basically be Constructor with animation set(there is setAnimation method to change it) could I call the applied inheritance(there would be like "RunningEnemy" and "Shooting Enemy") Strategy pattern?(Their behaviour did change in a sense)
- I have multitude of door types. A doors that can be blasted by a bomb, a doors that can be normally opened by command, a doors that will open themselves when player is in near proximity and finally locked doors that need unlocking. If I made the appropriate change to this structure(Currently they use simple inheritance) could I transform it into Decorator pattern? (Like normal doors are decorated so that they open themselves, or they dont open unless unlocked etc). This however sounds more like strategy again than decorator.
- Maybe decorator for missiles?
Last option is to make custom weapon that probably counts 100% as decorator, but that sounds kinda cheap, because probably every second dude in our class will have something like that.
If none of the above fits for decorator, I wouldnt mind hearing some example that is close to this(not like the wikipedia "window with scroll bar") kind of assignment.
Thanks in advance for any input on this topic whoever read through this textwall.
A bit of background: Anything that can be shown on screen(has animation etc) is called Actor. There is AbstractActor that we wrote that has certain functionalities added on top of the Actor(actor has been provided as interface).
Important note: the Actor has method act, which is called by the library every frame on all actors present in the world.
The assignment has another part tho, that is, we have to create 10 Actors by ourselfs that are somewhat unique in their behaviour compared to what we did in the class.
That isnt much of a problem, the kicker is this:
We have to make use of:
1. State pattern
2. Observer pattern
3. Decorator pattern
4. Some behavioral patter of our choice except Null Object, Template Method and Iterator.
The first two are easy because they are also very self explanatory. However I have hard time getting the grip on the third, and coming up with something that could satisfy some behavioral pattern.
I thought of using Memento(as a Quick save/load functionality) but you may see that Srategy could also be used.(Command pattern is used somewhat in the assignment, so I can say I used that too)
I dont mind coding anything, and Im not asking for "do it for me", I just want a nudge or a confirmation of sorts, of whether the following can be considered Decorator pattern, or alternativelly Srategy, or some mix.
According to what I digged from wikia and from https://sourcemaking.com/design_patterns/behavioral_patterns I came up with following possible scenarios:
- I will have at least 2 enemies. One will try to chase you and when he touches you he deals damage. The other one will most likely be stationary but he will be looking at you and firing poisonous missiles at you(the poison and the missile are already coded).
If I made some barebone "framework" for the enemies which would basically be Constructor with animation set(there is setAnimation method to change it) could I call the applied inheritance(there would be like "RunningEnemy" and "Shooting Enemy") Strategy pattern?(Their behaviour did change in a sense)
- I have multitude of door types. A doors that can be blasted by a bomb, a doors that can be normally opened by command, a doors that will open themselves when player is in near proximity and finally locked doors that need unlocking. If I made the appropriate change to this structure(Currently they use simple inheritance) could I transform it into Decorator pattern? (Like normal doors are decorated so that they open themselves, or they dont open unless unlocked etc). This however sounds more like strategy again than decorator.
- Maybe decorator for missiles?
Last option is to make custom weapon that probably counts 100% as decorator, but that sounds kinda cheap, because probably every second dude in our class will have something like that.
If none of the above fits for decorator, I wouldnt mind hearing some example that is close to this(not like the wikipedia "window with scroll bar") kind of assignment.
Thanks in advance for any input on this topic whoever read through this textwall.