This is an extension of “Refactoring – code optimization” – a topic shared in DevDay 2015. This year, the presentation will focus on a more advanced topic but it is shown simply to help you optimize, restructure code, refactore better system thereby ensure easy software expanded, management and maintenance. That is the standard design in software programming. Maybe you’ve heard it with the word “Design Pattern”.
Join us to learn and share.
———
Speaker: Tuan Do – Scrum Master at Axon Active Vietnam
3. I’m Tuan
• Live in Da Nang.
• Working in Axon Active
Vietnam.
• 6 years in development
• Scrum Master, Team Leader,
Software Engineer.
• Java, Javascript, Code
Generator. tuan.do@axonactive.com
4. Questions
• Who joined Devday Da Nang 2015 ?
• Who knows about refactoring ?
• Who knows about clean code ?
6. What is a design pattern ?
“Each pattern describes a problem which occurs over
and over again in our environment, and then describes
the core of the solution to that problem, in such a way
that you can use this solution a million times over,
without ever doing it the same way twice”
- Christopher Wolfgang
Alexander (1936)
15. How to use a design pattern
(1 of 2)
• Read the pattern.
• Study the structure, participants and
collaborations sections.
• Sample code of pattern
• Choose names for pattern participants that are
meaningful in the application context.
16. How to use a design pattern
(2 of 2)
• Define the classes.
• Define application-specific names for operations
in the pattern.
• Implement the operations to carry out the
responsibillities and collaborations in the
pattern.
23. Factory Method
“Define an interface for creating an object, but let
subclasses decide which class to instantance.
Factory Method lets a class defer instantiation to
subclasses.”
26. Abstract Factory
• It isolates concrete classes.
• It makes exchanging product famillies easy.
• It promotes consistency among products.
• Supporting new kinds of products is difficult.
29. Adapter
“Convert the interface of a class into another
interface clients expect. Adapter lets classes work
together that couldn’t otherwise because of
incompatible interfaces.”
34. Composite
“Compose objects into tree structures to represent
part-whole hierarchies. Composite lets clients treat
individual objects and compositions of objects
uniformly.”
37. Composite
• Defines class hierarchies consisting of primitive
objects and composite objects.
• Make the client simple.
• Make it easier to add new kinds of components.
• Can make your design overly general.
42. Decorator
• More flexibility than static inheritance.
• Avoids feature-laden classes high up in the
hierarchy.
• A decorator and it’s component aren’t critical.
• Lost of little objects.
44. Observer
“Define a one-to-many dependency between
objects so that when one object changes state, all
its dependents are notified and updated
automatically.”
49. Strategy
“Define a family of algorithms, encapsulate each
one, and make them interchangeable. Strategy
lets the algorithm vary independently from clients
that use it.”
52. Strategy
• Families of related algorithms.
• An alternative to subclassing.
• Strategies eliminates conditional statements.
• Clients must be aware of different Strategies.
• Communication overhead between Strategy and
Context.
• Increased number of objects.
54. Template Method
“Define the skeleton of an algorithm in an
operation, deferring some steps to subclasses.
Template Method lets subclasses redefine certain
steps of an algorithm without changing the
algorithm’s structure.”