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 … More 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 … More 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. @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } 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 … More @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: public class Student implements … More 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 … More Comparable vs Comparator