Modeling/DesignPattern
-
CommandModeling/DesignPattern 2020. 2. 29. 16:29
1. Overview We want to represent a request or a method call as an object. Information about parameters passed and the actual operation is encapsulated in an object called command. The advantage of a command pattern is that what would have been a method call is now an object which can be stored for later execution or sent to other parts of code. We can now even queue our command objects and execu..
-
FlyweightModeling/DesignPattern 2020. 2. 28. 23:13
1. Overview Our system needs a large number of objects of a particular class and maintaining these instances is a performance concern. Flyweight allows us to share an object in multiple contexts. But instead of sharing the entire object, which may not be feasible, we divide the object state into two parts. intrinsic (the state that is shared in every context) and extrinsic state (context-specifi..
-
Dependency Inversion Principle (DIP)Modeling/DesignPattern 2020. 2. 28. 11:16
1. Overview High-level modules should not depend upon low-level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions. 2. Description 2.1 Dependency public void printMe() { System.out.println("Hello"); } printMe() method depends on out object defined in System Class. public void writeReport() { Report report = new Repo..
-
Interface Segregation Principle (ISP)Modeling/DesignPattern 2020. 2. 28. 11:14
1. Overview A client should not be forced to depend upon an interface that they do not use. 2. Description 2.1 Intuition 2.1.1 Interface Pollution Large Interfaces Unrelated Methods Classes have empty method implementations Method implementations throw UnsupportedOperationsException or similar Method implementations return null default/dummy values 3. Example 3.1 Violate ISP interface Persistenc..
-
Liskov Substitution Principle (LSP)Modeling/DesignPattern 2020. 2. 28. 00:51
1. Overview We should be to substitute base class objects with child class objects and this should not alter behavior/characteristics of the program. 2. Description For example, Java what we are also talking about behavioral subtypes. That means if the base class object was providing a specific behavior and if that base class object is now substituted with a child class object that behavior shou..
-
Open-Closed Principle (OCP)Modeling/DesignPattern 2020. 2. 26. 01:46
1. Overview Software entities such as Classes, Modules, Methods, and etc, should be open for extension but closed for modification. 2. Intuition Open for Extension: Extend existing behavior Closed for Modification: Existing code remains unchanged 3. Example 3.1 Violate OCP abstract class Subscriber {} class CallHistory { public static class Call { private LocalDateTime begin; private long durati..
-
Single Responsibility Principle (SRP)Modeling/DesignPattern 2020. 2. 26. 00:45
1. Overview There should never be more than one reason for a class to change. A class is focused, single functionality, and addresses a specific concern. 2. Intuition Guess an AwesomeClass which have communication protocol, message format, and authentication. When we have to change every HTTP to HTTPS, JSON to XML, and authentication, AwesomeClass should be changed. So Single Responsibility mean..
-
StateModeling/DesignPattern 2020. 2. 26. 00:43
1. Overview State pattern is a behavioral software design pattern that allows an object to alter its behavior when its internal state changes. This pattern is close to the concept of finite-state machines. The state pattern can be interpreted as a strategy pattern, which is able to switch a strategy through invocations of methods defined in the pattern's interface. State design pattern allows ou..