tag:blogger.com,1999:blog-8712770457197348465.post8936694492225047283..comments2024-03-17T23:01:26.872-07:00Comments on Javarevisited: Decorator Design Pattern in Java with Example Java Tutorialjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-8712770457197348465.post-84498137344261912152018-03-24T06:59:17.724-07:002018-03-24T06:59:17.724-07:00The blog here does not mention at all, why inherit...The blog here does not mention at all, why inheritance cannot do the same thing as the decorator design pattern. <br />With inheritance you can simply create the classes with extra functionality like USD and SGD (extending the Dollar class) and assign them at runtime to individual objects requiring extra functionality and for those which do not require extra functionality you can assign the Sasankhttps://www.blogger.com/profile/17421213913936887249noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-6662782850887485062018-03-23T23:55:13.290-07:002018-03-23T23:55:13.290-07:00"1. Component Interface: In our example ..."1. Component Interface: In our example Currency interface is component which used on its own or we need decorator for that."<br /><br />********************************************************************************************<br /><br />In your example, Component is an abstract class and not an interface.Sasankhttps://www.blogger.com/profile/17421213913936887249noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-72008861310919608632013-09-11T06:27:38.347-07:002013-09-11T06:27:38.347-07:00Please verify and let me know if my corrections fo...Please verify and let me know if my corrections for the programs described are correct or not...<br /><br />package com.decorator;<br /><br />public abstract class Currency {<br /><br /> String description = "Unknown currency";<br /><br /> public String getDescription() {<br /> return description;<br /> }<br /><br /> public abstract double cost(double value);<br /><br />}<br /><br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-60034903253391633012013-04-29T19:37:17.180-07:002013-04-29T19:37:17.180-07:00I agree that Decorator is one of the most useful d...I agree that Decorator is one of the most useful design pattern in object oriented language, not just java. I would like to add few key things, which I feel important to understand Decorator design pattern :<br /><br />- Decorator objects are part of same type hierarchy, they are decorating. For example if you are decorating Pizza then decorators like CanadianPizza, ItalianPizza or even Mohitnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-87795697450425245712013-04-19T10:45:06.856-07:002013-04-19T10:45:06.856-07:00SGDDecorator and USDDecorator doesn't implemen...SGDDecorator and USDDecorator doesn't implement the abstract methods it inherits. This code just will not compile as is.<br /><br />Please don't post examples that don't work<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-61372957269668338832013-03-28T02:03:07.080-07:002013-03-28T02:03:07.080-07:00I like the naming convention, having Decorator in ...I like the naming convention, having Decorator in the name of class, goes naming convention best practices, mentioned in Clean Code. By reading Decorator, any Java developer can recognize use of Decorator pattern.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-24075886982845341852012-12-29T04:01:23.350-08:002012-12-29T04:01:23.350-08:00SGDDecorator and USDDecorator doesn't implemen...SGDDecorator and USDDecorator doesn't implement the abstract methods it inherits. This code just will not compile as is. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-2539329913217670452012-12-05T05:43:40.283-08:002012-12-05T05:43:40.283-08:00In above code example, we have mention below code....In above code example, we have mention below code.<br />public String getDescription(){<br /> return currency.getDescription()+" ,its US Dollar";<br /> }<br />I see an error here that below line of code<br />return currency.getDescription()+" ,its US <br />should be replaced by <br />return currency.getCurrencyDescription()+" ,its US <br /><br />Anonymoushttps://www.blogger.com/profile/07837784489785848368noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-7588501899630494382012-12-02T02:28:00.209-08:002012-12-02T02:28:00.209-08:00I have written the following example :
Abstrac Co...I have written the following example :<br /><br />Abstrac Component :HouseComponent<br />Concrete Component Class :OneBedRoomHouse<br />Abstract Decorator :AbstractHouseDecorator<br />Concrete Decorator Class :OneBedRoomHouseWithCarSpaceDecorator <br />Concrete Decorator Class2 : OneBedRoomHouseWithSwimmingPoolDecorator<br /><br />Decorator Test class : DecoratorDemo<br />===========Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-2572913587983985462012-05-22T20:34:43.603-07:002012-05-22T20:34:43.603-07:00decorator design pattern was tricky for me, I neve...decorator design pattern was tricky for me, I never really found where to use decorators. I knew it was used in Java IO package but except that I don't really find any other use of decorator pattern. is there any specific guideline or point exist which helps to decide whether to use decorator pattern or not ?Vidhyahttp://en.wikipedia.org/wiki/Design_Patternsnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-40081419240987929262011-12-02T23:58:37.698-08:002011-12-02T23:58:37.698-08:00Decorator has been used by JDK itself including I/...Decorator has been used by JDK itself including I/O and collection classes.<br /><br />Read more design patterns for interview:<br /><a href="http://extreme-java.com/how-to-choose-design-patterns-for-java-interview/" rel="nofollow">Choosing Design Patterns for interview</a>Sandeephttps://www.blogger.com/profile/14459583259453333684noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-52686805688063082802011-11-19T21:16:22.725-08:002011-11-19T21:16:22.725-08:00A Comprehensive coverage of the Decorator Pattern ...A Comprehensive coverage of the Decorator Pattern Javin..<br /><br />Some general interview questions on J2EE Design patterns as a whole can be found by <a href="http://inheritingjava.blogspot.com/2011/05/j2ee-design-patterns-interview.html" rel="nofollow">Clicking Here</a><br /><br />AnandAnand Vijayakumarhttps://www.blogger.com/profile/04069290912727901147noreply@blogger.com