OOD teaches a complicated method, best for large systems. Here we teach the ten cent version. OO Design for the Rest of Us 1.

Slides:



Advertisements
Similar presentations
Study What’s that? Why? How?. School does not “do stuff” to you You do stuff to school – it is active You do stuff to school – it is active This is about.
Advertisements

Final project Steve Krug Don’t make me think. Principle #1 How we really use the web Have something on the page that catches the readers interest. -Users.
Mentoring A Younger Chemists’ Guide to a Career Essential.
9-May-15 Notes on Style Testing the TicTacToe game.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Inheritance Inheritance Reserved word protected Reserved word super
Language Issues for Inheritance CS 5010 Program Design Paradigms "Bootcamp" Lesson 12.3 © Mitchell Wand, This work is licensed under a Creative.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
Six compound procedures and higher-order procedures.
16-Jun-15 Recognizers. 2 Parsers and recognizers Given a grammar (say, in BNF) and a string, A recognizer will tell whether the string belongs to the.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Software Engineering Case Study Slide 1 Introductory case study.
© Dec. 2006, May 2009 Helmut Jilling (All rights reserved) Improvement Audits - Let’s Get More Bang! Note: This slide show is designed to let you view.
(c) University of Washington04-1 CSC 143 Java Inheritance Example (Review)
Warm-up Problem 2 Write three positive integers in a line. In the space just below and between each pair of adjacent integers, write their difference.
1 Design and Integration: Part 1 Nuggets about Design vs Project Management.
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
BCS 2143 Introduction to Object Oriented and Software Development.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Why you should be using Version Control. Matt Krass Electrical/Software Engineer November 22, 2014.
Unit 1 – Improving Productivity Ryan Taroni Instructions ~ 100 words per box.
Java Classes Using Java Classes Introduction to UML.
Senior Project By: Thomas Yates. Overview For my senior project, I decided to write my novel, which I’ve been working on for a few years. I have named.
More on “The Huddersfield Method” A lightweight, pattern-driven method based on SSM, Domain Driven Design and Naked Objects.
CSC 395 – Software Engineering Lecture 13: Object-Oriented Analysis –or– Let the Pain Begin (At Least I’m Honest!)
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
Prepping for the basecamp What’s in my backpack? my 360deg feedback report my colleagues’ suggestions my actions.
 Development is organized in a series of short, fixed-length mini-projects called iterations  Iterations are also incremental  Successive enlargement.
1 Planning – Agile Style Highsmith, Ch 7 All kinds of iterations! CSSE579 Session 3 Part 1.
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
Refactoring and Synchronization with the StarTeam Plug-in for Eclipse  Jim Wogulis  Principal Architect, Borland Software Corporation.
Refactoring & Testability. Testing in OOP programming No life in flexible methodologies and for refactoring- infected developers without SOME kind of.
1 CS161 Introduction to Computer Science Topic #9.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Salman Marvasti Sharif University of Technology Winter 2015.
Educational Networks What are they and why are they important?
Advanced OOD and the Strategy Pattern 1. In our last episode… (It was all about Object-Oriented Design) 2.
Design Patterns David Talby. This Lecture Re-routing method calls Chain of Responsibility Coding partial algorithms Template Method The Singleton Pattern.
This presentation will attempt to guide you through the information needed to solving harder equations of the type ax 2 + bx + c = 0 When you get to the.
In the “real world” we’re taught that design is pretty. Here we learn that design is about productivity. Introduction to Software Design 1.
Lesson 2: Reading a program. Remember: from yesterday We learned about… Precise language is needed to program Actors and Classes Methods – step by step.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
Ten Commandments of Word Processing. I. Thou shall not use spaces n Put no more than two spaces together. n Use the key to line things up. n Better yet,
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Creating a GUI Class An example of class design using inheritance and interfaces.
CS2102: Lecture on Abstract Classes and Inheritance Kathi Fisler.
Version Control and SVN ECE 297. Why Do We Need Version Control?
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
Blogs and Wikis. Collaboration col·lab·o·ra·tion /kəˌlæbəˈreɪʃən/ Show Spelled[kuh-lab-uh- rey-shuhn] Show IPA –noun 1. the act or process of collaborating.
(c) University of Washington10-1 CSC 143 Java Errors and Exceptions Reading: Ch. 15.
Safety methods within Agile and RUP methods TORGRIM LAURITSEN BUCS project.
1. Free Will and Determinism Determinism: given a specified way things are at a time t, the way things go thereafter is fixed as a matter of natural law.
Event-driven design will set you free The Observer Pattern 1.
My Observer Goes to 11 Model-View Controller 1. Which is the best class diagram? 2 ___Edge___ drop() _Vertex_ addEdge() dropEdge() _Iterable_ * 2 ___Edge___.
Classic Connections: Innovative Methods for Making Education Work.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
This I Believe Essay Writer’s Workshop: Introductions, Juicy Details, & Conclusions 8 th ELA St. Joseph School.
Computational Models of Discourse Analysis Carolyn Penstein Rosé Language Technologies Institute/ Human-Computer Interaction Institute.
Software Engineering Session 12 INFM 603. Software Software represents an aspect of reality –Input and output represent the state of the world –Software.
Introduction to Software Design
C++ coding standard suggestion… Separate reasoning from action, in every block. Hi, this talk is to suggest a rule (or guideline) to simplify C++ code.
Causes and Solutions to QuickBooks Payroll Error Code 2002 Globally acclaimed software QuickBooks is considered one of the best accounting and payroll.
CS2102: Lecture on Abstract Classes and Inheritance
Social Studies Methodology- Cause and Effect Organizers
Mediator to Model-View Controller
Topic 5: Communication and the Internet
ແຜນທີ່ຂັ້ນຕອນການດຳເນີນງານ Process Mapping
Presentation transcript:

OOD teaches a complicated method, best for large systems. Here we teach the ten cent version. OO Design for the Rest of Us 1

Ten Cent Object-Oriented Design Let’s do this. 2

Some (more) things we’d like to be true  I can drive the design from the user stories  The code just “writes itself”  My code will be easy to understand by the team  My code will be SRP and DRY 3

Reminder on SRP and DRY  S ingle R esponsibility P rinciple ( SRP )  Each class should be responsible for one thing (capability, entity, computation, etc.)  Can phrase this as “mind your own business”  object do its own calculations  object should not do calculations for another  Easy to violate this because objects need to be connected to one another  e.g., Events happen as part of Dates  D on’t R epeat Y ourself ( DRY )  Each computational idea should be expressed just once  Violations often the result of  cut-and-paste programming  incomplete class (others have to do calculations for it, which also violates SRP)  But also over-specialization of classes (class = object)

A Concise Theory of Object-Oriented  Object represents a “thing”  person, car, date, …  (not two things, not ½ thing)  Object responds to messages  (method calls)  Things it does to itself (SRP)  That is, other objects ask the object to do something to itself  Objects are “opaque”  Can’t see each others’ data/vars  Messages (calls) are only way to get things done 5

A Concise Theory of Object-Oriented, II  Because objects are completely opaque, we don’t need to know what’s really inside them  Each car object could be implemented with its own unique code  If two cars behave the same, then really should have same code  Otherwise would violate DRY  And a huge amount of coding work  So all cars are made from a common car template  Template = class  The car template is not a car, it’s a “blueprint” for a car  Helps satisfy DRY 6

myCity’s Show Friends on Map Story Rule Write code so that it sounds like the specification. I call this “coding to the specification” Recall that OO theory and SRP dictate objects that:  represent a “thing”  respond to messages about itself This suggests the start of a design process 1.Identify the “things” 2.Identify their messages 3.Assemble into classes 4.Right things call right messages 7 As a user I want see my nearby friends on the map So that I know who to contact for a spontaneous meet-up Given I am logged in And my location is known When my friends are online And my friends’ location is known And my friends are near me Then I see them on the map

myCity’s Show Friends on Map Story, II 1.Identify the “things”  me (previous user story)  friends, friend  map (previous) 2.Identify the messages  me.logged-in (previous)  friend.location-known  friend.location  friend.online  friend.near(me)  friend.image 3.Assemble into classes (TBD) 4.Right things call right messages (TBD) 8 Given I am logged in And my location is known When my friends are online And my friends’ location is known And my friends are near me Then I see them on the map As a user I want see my nearby friends on the map So that I know who to contact for a spontaneous meet-up  Note how messages “sound like” the specification  Plural objects may be list/set of singular  Classes for some objects may already exist  Look for new messages  May find repetitive messages  e.g., location-known vs. location?  maybe location just returns null (or not)  Implied messages  “see them on the map” −> something to see

myCity’s Show Friends on Map Story, III 9 As a user I want see my nearby friends on the map So that I know who to contact for a spontaneous meet-up class Friend { Location location(); // null −> not-known boolean online(); Bitmap image(); } class Friends implements Iterable { Friends online(); Friends locationKnown(); // −> online? } 1.Identify the “things”  me (previous user story)  friends, friend  map (previous, built-in) 2.Identify the messages  me.logged-in (previous)  friend.location-known  friend.location  friend.online  friend.near(me)  friend.image 3.Assemble into classes 4.Right things call right messages (TBD) Given I am logged in And my location is known When my friends are online And my friends’ location is known And my friends are near me Then I see them on the map

myCity’s Show Friends on Map Story, IV 10 class Friend { Location location(); // null −> not-known boolean online(); Bitmap image(); } class Friends implements Iterable { Friends online(); Friends locationKnown(); // −> online? } Given I am logged in And my location is known When my friends are online And my friends’ location is known And my friends are near me Then I see them on the map  This is the hardest part  What thing does something to itself so friends get drawn on map?  Not mentioned in scenario!  Map? Predefined in Android  How about a FriendMap?  A map with added responsibility of drawing my friends  Let’s take a look at this 4.Right things call right messages

myCity’s Show Friends on Map Story, IV 11 class Friend { Location location(); // null −> not-known boolean online(); Bitmap image(); } class Friends implements Iterable { Friends online(); Friends locationKnown(); // −> online? } Given I am logged in And my location is known When my friends are online And my friends’ location is known And my friends are near me Then I see them on the map  This is the hardest part  What thing does something to itself so friends get drawn on map?  Not mentioned in scenario!  Map? Predefined in Android  How about a FriendMap?  A map with added responsibility of drawing my friends  Let’s take a look at this 4.Right things call right messages

myCity’s Show Friends on Map Story, V 12 class Friend { Location location(); boolean online(); Bitmap image(); } class Friends implements Iterable { Friends online(); Friends locationKnown(); // −> online? } Given I am logged in And my location is known When my friends are online And my friends’ location is known And my friends are near me Then I see them on the map class NearbyFriendsMap extends GoogleMap { private Friends friends; private GoogleMap map; NearbyFriendsMap(GMap map, Friends friends); void showNearbyFriends(); // reimplement every GM method so that it re-calls // the method on map. Called delegation. E.g. Marker addMarker(…) { map.addMarker(…); } }  Is a map, plus nearby friend stuff  Dual responsibilities (Map things, Friend drawing)  Huge amount of work (reimplement all methods)  Illegal in Android: GoogleMap is a “final” class!  SRP implies class that just does drawing friends 4.Right things call right messages

myCity’s Show Friends on Map Story, VI 13 class Friend { Location location(); boolean online(); Bitmap image(); } class Friends implements Iterable { Friends online(); Friends locationKnown(); // −> online? } Given I am logged in And my location is known When my friends are online And my friends’ location is known And my friends are near me Then I see them on the map  Basic idea is an intermediary whose Single Responsibility is drawing my friends on the map class NearbyFriendsTracker { private Friends friends; private GoogleMap map; NearbyFriendsTracker(GMap map, Friends friends); void showNearbyFriends(); }  Single responsibility : drawing friends on map!  Don’t have to bunch of “extra” methods  Very similar, despite SRP  Still trying to make code sounds like specification 4.Right things call right messages

UML Diagram: Subclass Approach 14 __NearbyFriendsMap__ - GoogleMap map - Friends friends −−−−−−−−−−−−−−−−− + showNearbyFriends() _________Friends_________ - List friends −−−−−−−−−−−−−−−−− + Friends online() + Friends locationKnown() _GoogleMap_ … _________Friend_________ + boolean online() + Location location() + Bitmap image() * _Iterable_ …

UML Diagram: Middleman Approach 15 _NearbyFriendsTracker_ - GoogleMap map - Friends friends −−−−−−−−−−−−−−−−− + showNearbyFriends() _________Friends_________ - List friends −−−−−−−−−−−−−−−−− + Friends online() + Friends locationKnown() _GoogleMap_ … _________Friend_________ + boolean online() + Location location() + Bitmap image() * _Iterable_ …

Take Aways  Design method combines a few guidelines  find things and messages  pack into SRP classes  make code sound like the specification  Non-trivial, takes experience  plural thing implies singular things  messages that don’t quite work  “Missing” (implied) things and messages  May take multiple tries on harder parts  Very common to revise after the fact (refactor)  New insights, new features benefit from diff. design 16

Take-Aways from Class Today  Object-oriented design is intuitive, but subtle  Java is just a tool, does not guarantee good design  (Just because I have an expensive camera does not make me a good photographer :)  Easy to put functionality in wrong place, make classes too big, or make too small  Possible to diagnosis and repair a design before or after the coding (may require both)  SRP, DRY  Change in one class affects another (SRP)  Small change affects multiple classes or methods  Unfortunately, there are many kinds of design mistakes, and unique repairs for them 17

Good-Enough is the “ 80/20 Rule ”  Returns on engineering investment are not linear  80 percent of the benefit for 20% of the effort  Diminishing returns for investment after that (other 80% of effort and only 20% gain)  Also known as Pareto Principle 18 small effort big gain