aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Decorator Design Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Decorator Design Pattern" Watch "Decorator Design Pattern" New topic
Author

Decorator Design Pattern

Anup Om
Ranch Hand

Joined: Dec 30, 2009
Posts: 62
Hello,
This is what I read about decorator design pattern.

Decorators prove more flexible than inheritance because the relationship between decorators and the objects they decorate can change at runtime, but relationships between base classes and their extensions are fixed at compile time.


Can someone please help me understand what it means by "relationship between decorators and the objects they decorate can change at runtime".

Thanks for your help in advance.


SCJP6
Adrabi Abderrahim
Greenhorn

Joined: Jan 23, 2011
Posts: 8

hello,

I tell you what I've understand from decorator pattern ,

decorator is like you buy a Playstation or any other thing, you can custom style by yourself (change at runtime), but you can't change into Playstation "base class", euh, in other word classes that decorate your object can be changed at runtime, example:

you've one class base 'X', and two classes for decoration 'Y', 'Z', and you've many possibilities to decorate 'X',


Z and Y is changeable in runtime, but X no,
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2495
    
    8

Welcome to the Ranch, Adrabi.


OCUP UML fundamental and ITIL foundation
youtube channel
Adrabi Abderrahim
Greenhorn

Joined: Jan 23, 2011
Posts: 8

thank you, dear Jan Cumps
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 992
    
    2
here you can fine most of design patterns with good examples:

http://javapapers.com/category/design-patterns/
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

You can see the Decorator pattern in action in the little icon beside a file or folder name in a GUI such as Windows Explorer or Finder in OS X. If you have installed a client extension for Subversion, for example, you will see the icon for files and folders "decorated" with some additional icon that indicates the state of that file or folder with regard to Subversion (new, modified, in conflict, not changed, etc.) This "decoration" can change at runtime as you perform actions on your files and folders. On my Mac, when I first create a file, its icon will be decorated with a little question mark to indicate that Subversion hasn't been told what to do with it yet. When I add the file or folder to Subversion, its icon will be decorated with a "+" sign to indicate that it has been added but not committed. And so on. That is to say, the "is a" relationship is temporal / can change over time and the relationship is conditional. In this example, "This file is a file that Subversion isn't tracking" is only true for a while, until you do something that makes this no longer true.

On the other hand, when you extend a class, the "is a" relationship between the parent and child classes is unconditional, lasts much longer, and cannot be changed at runtime.


Junilu - [How to Ask Questions] [How to Answer Questions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Decorator Design Pattern