E N D
STANDARD DECORATOR DESIGN IN JAVA WITH JAVA EXAMPLE https://www.besanttechnologies.com/training-courses/java-training
STANDARD DECORATOR DESIGN IN JAVA WITH JAVA EXAMPLE • I was thinking about writing about the decorator design pattern in Java when I first wrote 10 interview questions in the Singleton Pattern in Java. • As the design pattern It is very important in the creation of software and is equally important in any main Java interview,
STANDARD DECORATOR DESIGN IN JAVA WITH JAVA EXAMPLE • it is always good to have a clear understanding of several design standards in Java. In this article, • we will explore and learn the standard Decorator Design in Java, which is a prominent design pattern in Java and you can see much of its example in the JDK itself. • JDK uses the decorator standard in the IO package, where it decorated the Reader and Writer classes for various scenarios, for example,
STANDARD DECORATOR DESIGN IN JAVA WITH JAVA EXAMPLE • BufferedReader and BufferedWriter are examples of decorator design patterns in Java. From the perspective of the project, • it is also a good idea to learn how existing things work in the JDK itself, for example. As HashMap works in Java or how the SubString method works in Java, • this will give you an idea of the things you need to take into account when designing your class or interface in Java. • Now let's go to the Decorator standard in Java.
STANDARD DECORATOR DESIGN IN JAVA WITH JAVA EXAMPLE • The decorator design pattern is used to improve the functionality of a specific object at runtime or dynamically · • At the same time, other instances of the same class are not affected by this individual object to obtain • The design pattern of the decorator is based on abstract classes and we derive the concrete implementation of these classes. • It is a structural design pattern and more used. is resolved by the Decorator standard: Now the question is why this pattern came into existence,
STANDARD DECORATOR DESIGN IN JAVA WITH JAVA EXAMPLE • what is the problem with the existing system, then, the answer is: if someone wants to add some functionality to an individual object or change the status of a certain object at runtime, • what is possible is not possible. We can provide the specific behavior to the entire object of this class at design time by inheritance help or by using the subclass, • but the Decorator pattern makes it possible for us to provide individual object of the same class with a specific behavior or state at runtime.
STANDARD DECORATOR DESIGN IN JAVA WITH JAVA EXAMPLE • This does not affect another the object of the same class in Java. When using the Decorator pattern in Java · • When the subclass is impractical and we need a large number of different possibilities to create an independent object or we can say that we have a number of combinations for an object. • When we want to add functionality to the individual object and not to every object at runtime, we use the design pattern of the decorator.
STANDARD DECORATOR DESIGN IN JAVA WITH JAVA EXAMPLE • Explanation of the code: We can understand this in the following term: Interface 1.Component: In our example, • the currency interface is a component that is used alone or we need a decorator for that.Component 2.Concrete: implement Compo nent and add new behavior to this object dynamically. • Dollar and Rupee are the concrete application of the coin.3.Decorator: Decorator contains a relation in a simple word,
STANDARD DECORATOR DESIGN IN JAVA WITH JAVA EXAMPLE • we can say that it has an instance variable that contains reference for the component that implement the same component that they are going to decorate. • Here a decorator is an abstract class that extends the currency.4.Decoration of concrete: it is an implementation of the Decorator.
STANDARD DECORATOR DESIGN IN JAVA WITH JAVA EXAMPLE • Then, dollar dollar and dg dollar are the implementation of the decorator contains instance variable for the interface of the component or the thing they are going to decorate. • Vantage of the design pattern Decorator in Java In summary,
STANDARD DECORATOR DESIGN IN JAVA WITH JAVA EXAMPLE • To get the decorator master's domain, I suggest looking inside the JDK library itself and discover what classes are decorated, because they are decorated. • Think also about the scenario where inheritance is impractical and you have more flexibility and try to use the decorator pattern in Java.