CPSC 872 John D. McGregor Session 21 Architecture Design, cont’d
Specification and design problem solution specification implementation specification
Styles us/library/ee aspx us/library/ee aspx Pipeline style – us/library/ff aspx us/library/ff aspx Layered style
Styles – 2: Control Loop
Closed loop control style Monitors fluctuating variable Takes action when violates boundary Sensitivity of thermostat
Design Patterns Singleton – ngleton_pattern.htm ngleton_pattern.htm Observer – bserver_pattern.htm bserver_pattern.htm
Pattern Pattern Name (Scope, Purpose) Intent Also Known As Motivation Applicability Structure Participants Collaborations Consequences Implementation An implementation Sample Code and Usage Program Listing Known Uses Examples of the pattern found in real systems. Related Patterns
Language Idioms class Person { String name; int birthYear; byte[] raw; public boolean equals(Object obj) { if (!obj instanceof Person) return false; Person other = (Person)obj; return name.equals(other.name) && birthYear == other.birthYear && Arrays.equals(raw, other.raw); }
Stream manipulation public interface InputStreamAction { void useStream(InputStream stream) throws IOException; } // Somewhere else public void executeWithFile(String filename, InputStreamAction action) throws IOException { InputStream stream = new FileInputStream(filename); try { action.useStream(stream); } finally { stream.close(); } }
Putting it all together Identify quality attributes that are important Prioritize them Select patterns that will enhance the most important quality attribute Refactor Repeat with next most important QA
Running example The system architecture looks like: Car OBD Phone Cloud