Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Design pattern
1. Contents
• Rewind the SOLID Principle
• Brief Introduction of Pattern Type
• Command Pattern
Example
• Visitor Pattern
Example
• Strategy Pattern
Example
2. Problem
• 1-Find out sum of below numbers
45389 + 58942
a) 453263 b)983835
c) 104345 d) 104331
3. Problem
• 2- Find out the Sum of below numbers:-
( 234000 + 56790)
a) 290799 b) 290720
c) 290755 d) 290790
4. Problem
3-Find out the sum of below numbers
89436 + 53459
a) 143895 b) 132895
c) 142295 d) 142895
5. • Given problems if you will see we are trying to implement the
Elimination technique to eliminate the options.
• Use case when we are giving any entrance exam and we have very
less time , we will try to implement this technique
• But the same technique we are not able to implement in third
problem, it is taking time so every pattern have their own use case.
• So Don’t apply technique in every use case
• So the patterns are technique to resolve recurring problem
6. Always Remember-
• Principle ! = Rule
• Principle Should
• Rule Must
• Principle are use to make the code reusable and increase the
readability
15. Dependency Inversion Principle (DIP)
High-level modules should not depend on low-level modules. Both should depend on abstractions.
Abstractions should not depend on details. Details should depend on abstractions
20. Command Pattern
• Command Design Pattern is used to encapsulate a request as an
Object[Command]
• and pass to an Invoker,
• wherein Invoker does not knows how to service the request but uses
encapsulated command to perform an action.
34. Command Design Pattern
• Why do we need a “receiver” in the Command design pattern
• We can also Complete Action from Concrete Command:
35. Answer is
• Pattern Comes from Problems.
• Design Pattern are recurring solutions to common problems of
design!
• Hence As the Problem describe at the end Receiver has to complete
all action
• Like in Hotel Example Cook has to cook all items.
36. Benefits
• 1- Code Readability by removing if else conditions
• 2- Invoker does not know how to execute the commands.
• 3- Converting the methods into objects.
• 4- We can extend the new commands.(open/close)
• 5- Same code will work for multiple receivers By extending the
Ireceiver
• 6- We can perform Undo and Redo Actions
• 7-Security extension, or interface exposure
• Using a command interface, you can also limit access to your objects,
allowing you to define another level of security
37. Drawback
• The main disadvantage of the Command pattern is the increase in the
number of classes for each individual command.
• However the command pattern classes are more readable than
creating multiple methods using if else condition.
40. Visitor Design Pattern
• If I have to add new operation like Sound() then we have to change
and add new operation all class and interface
• For resolving such kind of problem we use Visitor Pattern.
41. Visitor Design Pattern
• The Visitor pattern represents an operation to be performed on the
elements of an object structure without changing the classes on
which it operates.
50. Strategy Design Pattern
• The strategy pattern (also known as the policy pattern) is a
behavioral software design pattern that enables an
algorithm's behavior to be selected at runtime. The strategy
patterns
• defines a family of algorithms,
• encapsulates each algorithm, and
• makes the algorithms interchangeable within that family.