Posts

Showing posts from November, 2023

Proxy Design Pattern Using Spring AOP

Image
 Proxy design pattern provides an object of a class with the functionality of another class with having it. This pattern comes under the structural design pattern of GOF Design Patterns. Spring provides two ways to create the proxy in the application.    1.JDK    2.CGLIB                                                                                                                                                                                          JDK proxy            ...

Strategy Design Pattern

  If you have multiple conditions (equivalent to multiple if-else statements) within a switch statement and you want to refactor them using the strategy pattern, you can create a strategy for each condition. Let's use an example of a system that calculates shipping costs based on the destination and weight of a package. public class ShippingCalculator { public double calculateShippingCost (String destination, double weight) { double cost; switch (destination) { case "Local" : if (weight <= 5 ) { cost = 5.0 ; } else { cost = 8.0 ; } break ; case "Domestic" : if (weight <= 5 ) { cost = 10.0 ; } else { cost = 15.0 ; } break ; case "International" : if (weig...