Design pattern at times plays an important role in building robust software application. In this slide presented one example where applying object adapter design pattern became handy.
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Case Study Design Pattern - Object Adapter
1. Case Study Design Pattern
- Object Adapter
Seungjin Lee
sj.sweetest@gmail.com
2. Product Domain : Logging Service in Java
š Gathers logs from different sources
šServers, Apps, Devices
š Provides log management / analysis functionality
šLog search, analysis, alert etc
š Today’s focus will be client SDK, which collect logs from user
application and transfer them.
3. Requirement
š For popular logging frameworks in Java
šWe need to support custom appender extension
šThat captures and sends logs to our system “e.g. Super Securely”
4. Problem
š How to get the message of the log differs in each framework
šLog4j: Log4jEvent.getMessage().toString()
šLogback: LogbackEvent.getFormattedMessage()
š Same is true of many other functionalities
š ...And that resulted in A LOT of duplicated codes W/O proper
design pattern
6. Feature request : Support Log4j2 framework
š ...Are we supposed to create another copy and modify here and
there?
7. Idea
š What if we create an interface
šthat specifies method signatures that we need
š And extend it for each framework that we support
šExtension class makes use of framework’s own API so as to
implement methods defined in the interface
š ...what turned out to be so called “Object Adapter Design Pattern”
11. Applying it to theory
OurLogEvent Interface
OurLog4jEvent / OurLogbackEvent / OurLog4j2Event
Log4jEvent / LogbackEvent / Log4j2Event
12. Summary: Pros of using object adapter
š Reduce or even remove duplicated codes
š Better
šMaintainability
šSeperation of concerns
šTestability
š...Looking