Clean Boundaries. Christopher Simpkins Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS / 10

Similar documents
CS 2340 Objects and Design

Testing. Christopher Simpkins Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS / 13

CS 2340 Objects and Design

CS 2340 Objects and Design - Scala

CS 1331 Introduction to Object Oriented Programming

Clean Formatting. Christopher Simpkins Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS / 1

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming

Clean Classes. Christopher Simpkins Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS / 11

Introduction to Object-Oriented Programming

Clean Functions. Christopher Simpkins Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS / 1

Introduction to Object-Oriented Programming

Tecniche di Progettazione: Design Patterns

Lecture 13: Design Patterns

Pattern Resources. Lecture 25: Design Patterns. What are Patterns? Design Patterns. Pattern Languages of Programming. The Portland Pattern Repository

CS 2340 Objects and Design

Introduction to Object-Oriented Programming

Facade and Adapter. Comp-303 : Programming Techniques Lecture 19. Alexandre Denault Computer Science McGill University Winter 2004

Tecniche di Progettazione: Design Patterns

Write for your audience

Functional Objects. Christopher Simpkins CS 3693, Fall Chris Simpkins (Georgia Tech) CS 3693 Scala / 1

ADAPTER. Topics. Presented By: Mallampati Bhava Chaitanya

Design Patterns IV Structural Design Patterns, 1

Design Patterns IV. Alexei Khorev. 1 Structural Patterns. Structural Patterns. 2 Adapter Design Patterns IV. Alexei Khorev. Structural Patterns

Introduction to Object-Oriented Programming

Control Structures. Christopher Simpkins CS 3693, Fall Chris Simpkins (Georgia Tech) CS 3693 Scala / 1

Introduction to Object-Oriented Programming

Clean Comments and Formatting

L23.1 Introduction... 2

Functions, Closures and Control Abstraction

Microsoft Office 365 for Business. Your office-on-the-go. Get more work done virtually anytime, anywhere, on any device.

Introduction to Object-Oriented Programming

Chris Simpkins (Georgia Tech) CS 2316 Data Manipulation for Engineers Python Overview 1 / 9

CS 2340 Objects and Design

Introduction to Object-Oriented Programming

AI and Security: Lessons, Challenges and Future Directions. Taesoo Kim

Human-Computer Interaction Design

BOUNDLESS IDENTITIES CAMPUS TECH TALKS NOVEMBER 4, Nathan Dors Lauren Manes Sarah Squire

Declaring and ini,alizing 2D arrays

Testing and Debugging

Design Patterns Revisited

Adapter Pattern Structural

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

Getting Started with Yammer Nicolas Kanaris July 2016 Cyprus Pedagogical Institute #ATS2020

Ministry Platform: The Portal

Testing and Debugging

CISC 322 Software Architecture

An Introduction to Patterns

Threads CS1372. Lecture 13. CS1372 Threads Fall / 10

Audience: Info Workers, Dev

Learning objec-ves. Declaring and ini-alizing 2D arrays. Prin-ng 2D arrays. Using 2D arrays Decomposi-on of a solu-on into objects and methods

EE/CprE/SE 491 Senior Design I and Professionalism. Design Document

Bridge Pattern. Used to decouple an abstraction from its implementation so that the two can vary independently

Contents. Enterprise Systems Maven and Log4j. Maven. What is maven?

CS 152 Computer Programming Fundamentals Coding Standards

INTERNAL ASSESSMENT TEST III Answer Schema

Designing. Simon Wilson Interaction designer, DWP Digital

Homework Assignment #3

Protecting your Data in the Cloud. Cyber Security Awareness Month Seminar Series

The Adapter Pattern. Interface with anything!

MongoDB Schema Design for. David Murphy MongoDB Practice Manager - Percona

BFH/HTA Biel/DUE/Course 355/ Software Engineering 2

From Clickstream to Research Stream

Gauging ADF Application Performance: Instrumenting Your Code

OODP Session 5a. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

COSC 3351 Software Design. Design Patterns Structural Patterns (I)

FACADE & ADAPTER CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 7 09/13/2011

Chapter 1 Introduction

Object-Oriented Oriented Programming Adapter Pattern. CSIE Department, NTUT Woei-Kae Chen

monolith to micro-services? event sourcing can help Doug

Thomas Pelaia II, Ph.D. XAL Workshop 2012 December 13, 2012 Managed by UT-Battelle for the Department of Energy

Lecture 3: Working with Data Structures

Rob Prouse

The ATCP Modeling Framework

Technical Interviews Kenny Yu

Software Engineering I (02161)

Step by Step process to activate guest access in Microsoft Teams.

MICROSOFT SHAREPOINT SITE OWNER S MANUAL. Creating a Useful, Engaging Site for your Team to Love

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

REVIEW- Reach Multiply BY MOSH BARI

How To: Chat and Q&A During Meetings

IT Decision Makers Unplugged

Should My Business Move to Office 365?

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming

Design to interfaces. Favor composition over inheritance Find what varies and encapsulate it

COMP-202: Foundations of Programming. Lecture 26: Image Manipulation; Wrap-Up Jackie Cheung, Winter 2015

Responsive Redesign dispatch.com 10tv.com thisweeknews.com

Nick Rozanski Andy Longshaw Eoin Woods. Sold! How to Describe, Explain and Justify your Architecture

The 2017 National Conference App Instruction Manual

Yammer. Getting Started. What Tool Do I Use?

Material and some slide content from: - GoF Design Patterns Book. Design Patterns #1. Reid Holmes. Lecture 11 - Tuesday October

Lecture 20: Design Patterns II

[Compatibility Mode] Confusion in Office 2007

Adapter & Facade. CS356 Object-Oriented Design and Programming November 19, 2014

20 Years of. Improve the Design of your Code. Dr Dimitris Dranidis JAVA Meetup Group, Thessaloniki May 2015

2/12/15. Template Method. Design Patterns. In Swing s JComponent. Template Method. Where do template methods come from? Making Template Methods

WELCOME TO KAPOST Kapost Content Planner Getting Started Guide

Scenario Based Install Jumpstart

Transcription:

Clean Boundaries Christopher Simpkins chris.simpkins@gatech.edu Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 1 / 10

Library Providers versus Library Users Tension between providers of an interface and users of an interface Providers want to produce maximally flexible and useful functionality for a wide audience. Users want to focus on their needs. This tension is particularly acute in standard library classes. Consider java.util.map... Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 2 / 10

A Key-Value Sensors Data Structure Say you have an application that needs to maintain sensors that are identified by ids. This is precisely what Maps are for, so you use a Map. But... your code passes around sensors, and most parts of your app should only retrieve sensors from the Map, and java.util.map includes methods that allow users to delete items from the map. The provider of Map is providing flexibility we don t want. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 3 / 10

How to Deal with Overly General Library Classes If we use Map to hold sensors, we end up with code like this: Map<Sensor> sensors = new HashMap<Sensor>();... Sensor s = sensors.get(sensorid ); There s a concept here that s begging to be represented in our system: public class Sensors { private Map<String, Sensor> sensors = new HashMap<>(); } public Sensor getbyid(string id) { return sensors.get(id); } //... Wrapping not necessary for every use of Map, but generally not a good idea to pass Maps around. This wrapping technique is a good general approach to deal with overly general third-party libraries at boundaries. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 4 / 10

Exploring and Learning Boundaries When you need a capability, you can write the code yourself, or use a library that provides the capability. If a libary is available, buy, don t build. Still have to learn the library. Instead of studying documentation, write learning tests. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 5 / 10

Learning log4j Using Third Party Code We write a simple test the way we think the library should work: @Test public void testlogcreate() { Logger logger = Logger.getLogger("MyLogger"); logger.info("hello"); } When the test runs, we get an error saying that we need an Appender, so we look up Appenders in thr docs and update our test: @Test public void testlogaddappender() { Logger logger = Logger.getLogger("MyLogger"); ConsoleAppender appender = new ConsoleAppender(); logger.addappender(appender); logger.info("hello"); } This time we get an error about a missing output stream,... Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 6 / 10

Learning Tests Lead to Boundary Tests... so we read a little more and come up with: @Test public void testlogaddappender() { Logger logger = Logger.getLogger("MyLogger"); logger.removeallappenders(); logger.addappender(new ConsoleAppender( new PatternLayout("%p %t %m%n"), ConsoleAppender.SYSTEM_OUT)); logger.info("hello"); } After a few more iterations of writing tests and reading docs, we know how log4j works and we have a set of tests with example code. These tests are boundary tests that use the library the same way as our production code. When a new version of the library is released, we can test it with our boundary tests before integrating it with production code. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 7 / 10

The Adapter Pattern 1 (A.K.A Wrapper) Intent: Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn t otherwise because of incompatible interfaces. Structure Participants Target defines the domain-specific interface that Client uses. Client collaborates with objects conforming to the Target interface. Adaptee defines an existing interface that needs adapting. Adapter adapts the interface of Adaptec to the Target interface. 1 GoF, Design Patterns, 1994 Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 8 / 10

Integrating Future Code Imagine we re a team writing an application that will use a hardware transmitter, but the transmitter s software is handled by another team that hasn t defined their software interface. We can define our own interface the way we want it to work. While we re waiting for the transmitter team, we create a fake implementation to work with. When the transmitter team finally gives us their interface, we can write an adapter to fit it to our interface. The rest of our code is unaffected. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 9 / 10

Final Thoughts on Boundaries Third-party libraries out of our control. Boundary tests minimize surprises when migrating to new versions of libraries. Minimize the number of places in our code that accesses third-party libraries. Sequester third-party libraries in boundary code using the adapter pattern. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 10 / 10