Skip to main content

Posts

Showing posts from September, 2019

Builder Design Pattern In Java

Greetings! Builder design pattern is a creational design pattern which helps us creating objects. According to GoF, Builder design pattern; "Separate the construction of a complex object from its representation so that the same construction processes can create different representations." Eventhough the original pattern description talked about complex object creation, most used scenario is to help constructing objects fluently. Builder design pattern helps us to assemble objects part by parts hiding inner states. In this post i'm going to talk only about normal object creation using this pattern. As I said earlier, this is a convienient way to construct objects with many parameters. Let's say you have a class which needs 10 parameters. Are you going to create a constructor with 10 arguments? Which is very difficult to maintain and use. This is where i'm giong to use Builder design pattern. Help to create objects with multiple parametes in simple...

Observer Design Pattern In Java

Greetings! Greetings! Observer design pattern falls into behavioral category. Observer design pattern is useful when we have multiple objects doing things according to another objects changes. This main object is callsed Subject and depending objects are called Observers. Subject and observers are loosely coupled and have no knowledge of each other. Subject(one) ----> Observer(many) Swing event listner, Spring listner are some examples for Observer desgin pattern. Observer design pattern according to GoF, "Define a one-to-many dependency between objects so that when one object changes state, all its dependencies are notified and updated automatically." Subject Maintain a list of observers who are interested in getting notified when something useful is happend. This provides methods to register the Observer, unregister the Observer and a method to notify all Observers at once. Observer Object which is interested in Subject's changes. Has ...