In a project im working on we hold a strict MVC structure. Im thinking of adding a decorator pattern to some of the modal windows (tiny popup windows) for those implementations where i whant some extra features.
So I basicly have the following:
SimpleModalWindowController.class
SimpleModalWindowModel.class
SimpleModalWindowView.class
EDIT: Question: Is it possible to implement a decorator pattern upon this for new ModalWindows implemenations or should i go with inheritance? I will have many different windows and I would like to combine some of there functionalities in the future.
If I go by decorator pattern, what class whould be the abstract one?
Would it be a class that combines all the above classes like SimpleModal.class to set them up as an abstract class or do I have more then one abstract class?
Im obviously new to this pattern and only got average OOP-skills, so please have some patience.
Thanks for any help.
/Marthin
I don't think this qualifies as a decorator pattern. What you are trying to do is create inheritance hierarchy with specialization (Fancy).
You don't need to implement Decorator. The way you are implementing looks fine if that is addressing the design issue. You don't have to use a pattern in this case.
This is how a decorator would be implemented which you don't need. I am a C# guy, hence syntax may not be fully correct.
abstract class ModalWindowModel
{
protected ModalWindowModel modalWindowModel; //This can be any class implementing/derived from ModalWindowModel
}
class SimpleModalWindowModel extends ModalWindowModel
{
SimpleModalWindowModel(ModalWindowModel modalWindowModel)
{
this.modalWindowModel = modalWindowModel;
}
// your other code goes here
}
class FancyModalWindowModel extends ModalWindowModel
{
FancyModalWindowModel(ModalWindowModel modalWindowModel)
{
this.modalWindowModel = modalWindowModel;
}
// your other code goes here
}
...
// Usage
ModalWindowModel simpleModalWindowModel = new SimpleModalWindowModel(null);
ModalWindowModel fancyModalWindowModel = new FancyModalWindowModel(simpleModalWindowModel);
....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With