Prototype Design Pattern

Builder design pattern belongs to creational design pattern family and this Prototype design pattern is used when we dont want to use either the new operator or create another factory class. i.e. we clone existing objects to create new ones. But How:  To implement the pattern, declare an abstract base class or interface that specifies a virtual clone() method. Any class that needs an object without using new operation, can derive … Continue reading Prototype Design Pattern

Builder Design Pattern

Builder design pattern belongs to creational design pattern family and this pattern is used to hide the complexity of object creation or the intent of the Builder design pattern is to separate the construction of a complex object from its representation. Example: When you buy a car, you have to go to showroom of the car. But the actual development (assembly) happens in somewhere in the factory … Continue reading Builder Design Pattern

@SpringBootApplication Annotation

@SpringBootApplication attribute is used to enable auto-configuration, component scan and to define extra configuration in a single application class. Though the same things can be achieved using following annotations individually @EnableAutoConfiguration: enable Spring Boot’s auto-configuration mechanism automatically configure your Spring application based on the jar dependencies that you have added. For example, if HSQLDBis configured in our classpath, and you have not manually configured any database connection beans, … Continue reading @SpringBootApplication Annotation

Cloneable in Java

Cloneable interface is one of the mistake in design in Java. At least I think so 🙂 A class should be implementing Cloneable interface if that class wants to be cloned along with overriding clone() method from Object class. This combination of compulsion makes it quite unusual to implement. Code below: As you can see Student Class is implementing Cloneable interface and also overriding clone() … Continue reading Cloneable in Java

Comparable vs Comparator

Comparable and Comparator both the interfaces are used to sort Collection of objects in certain order. Implementing Comparable interface allows us to achieve default or natural ordering where implementing a Comparator allow us to sort Collection in other than natural ordering. Comparable interface imposes a total ordering on the objects of each class that implements it. This ordering is referred to as the class’s natural ordering and … Continue reading Comparable vs Comparator