sd2x3.1 motivating software design chris€¦ · uml class diagram (detailed) sd2x-3.4 11 uml class...

281
SD2x-3.1 1 Property of Penn Engineering, Chris Murphy SD2x3.1 Motivating Software Design Chris

Upload: dinhkhue

Post on 01-Apr-2018

233 views

Category:

Documents


3 download

TRANSCRIPT

  • SD2x-3.1 1Property of Penn Engineering, Chris Murphy

    SD2x3.1

    Motivating Software Design

    Chris

  • SD2x-3.1 2Property of Penn Engineering, Chris Murphy

    Fred Brooks

  • SD2x-3.1 3Property of Penn Engineering, Chris Murphy

    Fred Brooks

  • SD2x-3.1 4Property of Penn Engineering, Chris Murphy

    There is no single development, in either

    technology or in management technique, that by itself

    promises even one order-of-magnitude improvement in productivity, in reliability, in

    simplicity.

  • SD2x-3.1 5Property of Penn Engineering, Chris Murphy

    I believe the hard part of building software to be the specification, design, and testing of this conceptual construct, not the labor of

    representing it and testing the fidelity of the representation.

  • SD2x-3.1 6Property of Penn Engineering, Chris Murphy

    Complexity: Too complex for one person to understand

    Conformity: Interfaces with different users, systems, etc.

    Changeability: Software is infinitely malleable

    Invisibility: Difficult to diagram or visualize

    Essential Difficulties

  • SD2x-3.1 7Property of Penn Engineering, Chris Murphy

    Study after study shows that the very best designers produce

    structures that are faster, smaller, simpler, cleaner, and

    produced with less effort.

  • SD2x-3.1 8Property of Penn Engineering, Chris Murphy

    I think the most important single effort we can mount is

    to develop ways to grow great designers.

  • SD2x-3.1 9Property of Penn Engineering, Chris Murphy

    The process of converting a set of requirements into a software artifact (code)

    Doing so in such a way that the code is: easy to understand easy to change

    What is Software Design?

  • SD2x-3.1 10Property of Penn Engineering, Chris Murphy

    Software changes during its lifetime Fixing bugs Adding new features Using new libraries Improving efficiency

    Software that is well-designed facilitates those changes, saving time and money

    Why is Software Design so important?

  • SD2x-3.1 11Property of Penn Engineering, Chris Murphy

    1. Modeling: identify concepts and their relationships

    2. Choose the right architecture

    3. Create/Use appropriate data structures

    4. Use design patterns when appropriate

    5. Refactor (change the design) as necessary

    How do we design software?

  • SD2x-3.2 1Property of Penn Engineering, Chris Murphy

    SD2x3.2

    Domain Modeling

    Chris

  • SD2x-3.2 2Property of Penn Engineering, Chris Murphy

    1. Modeling: identify concepts and their relationships

    2. Choose the right architecture

    3. Create/Use appropriate data structures

    4. Use design patterns when appropriate

    5. Refactor (change the design) as necessary

    How do we design software?

  • SD2x-3.2 3Property of Penn Engineering, Chris Murphy

    1. Modeling: identify concepts and their relationships

    2. Choose the right architecture

    3. Create/Use appropriate data structures

    4. Use design patterns when appropriate

    5. Refactor (change the design) as necessary

    How do we design software?

  • SD2x-3.2 4Property of Penn Engineering, Chris Murphy

    How do we design classes?

  • SD2x-3.2 5Property of Penn Engineering, Chris Murphy

    Identify concepts (classes) Their properties (attributes/fields) Their behaviors (operations/methods) And the relationships between them

    Domain Modeling

  • SD2x-3.2 6Property of Penn Engineering, Chris Murphy

    Graduate and undergraduate students

    may apply to the program.The application consists

    of a recommendation letter and personal

    statement.

  • SD2x-3.2 7Property of Penn Engineering, Chris Murphy

    Assign roles based on parts of speech

    Noun: class or attribute

    Adjective: attribute or subclass

    Verb: operation

    Grammatical Parsing

  • SD2x-3.2 8Property of Penn Engineering, Chris Murphy

    Graduate and undergraduate students

    may apply to the program.The application consists

    of a recommendation letter and personal

    statement.

  • SD2x-3.2 9Property of Penn Engineering, Chris Murphy

    Graduate and undergraduate students

    may apply to the program.The application consists

    of a recommendation letter and personal

    statement.

  • SD2x-3.2 10Property of Penn Engineering, Chris Murphy

    Graduate and undergraduate students

    may apply to the program.The application consists

    of a recommendation letter and personal

    statement.

  • SD2x-3.2 11Property of Penn Engineering, Chris Murphy

    Nouns: Students Program Application Letter Statement

    Grammatical Parsing

    Adjectives: Graduate Undergraduate

    Verbs: Apply Consists

  • SD2x-3.2 12Property of Penn Engineering, Chris Murphy

    A noun should be a class if: it has multiple attributes and/or operations all attributes/operations are common to all

    instances of the class

    Otherwise it should likely be an attribute of another class

    Nouns: Classes or Attributes?

  • SD2x-3.2 13Property of Penn Engineering, Chris Murphy

    An adjective should represent a subclass of another class if: different adjectives would imply different or

    additional operations or behavior different adjectives would imply different

    attributes

    Otherwise, an adjective should be an attribute of a class

    Adjectives: Attributes or Subclasses?

  • SD2x-3.2 14Property of Penn Engineering, Chris Murphy

    Student may apply to the program Subject: student Direct object: program

    apply operation should go in Student class

    Certain verbs are more indicative of relationships between classes than they are of operations: contains, has, is, uses, consists

    Verbs: in which class do they belong?

  • SD2x-3.2 15Property of Penn Engineering, Chris Murphy

    Class: Student Attributes/Subclasses: Graduate; Undergraduate Operations: Apply

    Class: Letter Class: Statement Class: Application Class: Program

    Our design

  • SD2x-3.2 16Property of Penn Engineering, Chris Murphy

    Graduate Student is a Student Undergraduate Student is a Student

    Application consists of Letter and Statement

    Student uses Application

    Student is associated with Program

    Relationships?

  • SD2x-3.2 17Property of Penn Engineering, Chris Murphy

    Identify concepts, properties, behaviors, and relationships

    Use grammatical parsing to assign roles based on parts of speech Noun: class or attribute Adjective: attribute or subclass Verb: operation

    Recap: Domain Modeling

  • SD2x-3.3 1Property of Penn Engineering, Chris Murphy

    SD2x3.3

    UML Class Diagrams

    Chris

  • SD2x-3.3 2Property of Penn Engineering, Chris Murphy

    How do we represent a class design?

  • SD2x-3.3 3Property of Penn Engineering, Chris Murphy

    Graduate and undergraduate students

    may apply to the program.The application consists

    of a recommendation letter and personal

    statement.

  • SD2x-3.3 4Property of Penn Engineering, Chris Murphy

    Graduate and undergraduate students

    may apply to the program.The application consists

    of a recommendation letter and personal

    statement.

  • SD2x-3.3 5Property of Penn Engineering, Chris Murphy

    Graduate Student is a Student Undergraduate Student is a Student

    Application consists of Letter and Statement

    Student uses Application

    Student is associated with Program

    Relationships

  • SD2x-3.3 6Property of Penn Engineering, Chris Murphy

    General-purpose language for modeling/visualizing software architecture and design

    Adopted as standard by Object Management Group (OMG) in 1997 and International Standards Organization (ISO) in 2005

    Types of diagrams: Structural Behavioral

    UML: Unified Modeling Language

  • SD2x-3.3 7Property of Penn Engineering, Chris Murphy

    UML Class Diagram (Compact)

  • SD2x-3.3 8Property of Penn Engineering, Chris Murphy

    Class

    UML Class Diagram (Compact)

  • SD2x-3.3 9Property of Penn Engineering, Chris Murphy

    Realization (is-a)

    UML Class Diagram

  • SD2x-3.3 10Property of Penn Engineering, Chris Murphy

    Generalization: one is a specialized form of the other and provides additional behavior/attributes

    Realization: one is the realization/actualization of the model that the other supplies

    In Java: Generalization = extends a (concrete) class Realization = implements an interface

    is-a Relationships in UML

  • SD2x-3.3 11Property of Penn Engineering, Chris Murphy

    Aggregation (has-a)

    UML Class Diagram

  • SD2x-3.3 12Property of Penn Engineering, Chris Murphy

    Aggregation: one class is part of another and can exist independently

    Composition: one class is part of another but cannot exist independently

    In Java, both are implemented by having one class as a field/attribute of another

    has-a Relationships in UML

  • SD2x-3.3 13Property of Penn Engineering, Chris Murphy

    Dependency (uses)

    UML Class Diagram

  • SD2x-3.3 14Property of Penn Engineering, Chris Murphy

    Dependency (uses): class A uses class Bs operations/attributes but class B is not part of A

    Aggregation/Composition (has): class B is part of class A

    In Java, dependency is exhibited when a class is a parameter or local variable in another class, but is not a field

    uses vs. has in UML

  • SD2x-3.3 15Property of Penn Engineering, Chris Murphy

    Association

    UML Class Diagram

  • SD2x-3.3 16Property of Penn Engineering, Chris Murphy

    Generalization

    Realization

    Aggregation

    Composition

    Dependency

    Association

    Recap: UML Class Relationships

  • SD2x-3.4 1

    SD2x3.4

    Detailed Class Diagrams

    Chris

  • SD2x-3.4 2

    How do we represent more details about a

    class design?

  • SD2x-3.4 3

    UML Class Diagram (Compact)

  • SD2x-3.4 4

    UML Class Diagram (Compact)

  • SD2x-3.4 5

    UML Class Diagram (Compact)

  • SD2x-3.4 6

    UML Class Diagram (Compact)

  • SD2x-3.4 7

    UML Class Diagram (Compact)

  • SD2x-3.4 8

    UML Class Diagram (Compact)

  • SD2x-3.4 9

    UML Class Diagram (Compact)

  • SD2x-3.4 10

    UML Class Diagram (Detailed)

  • SD2x-3.4 11

    UML Class Diagram (Detailed)

  • SD2x-3.4 12

    UML Class Diagram (Detailed)

  • SD2x-3.4 13

    UML Class Diagram (Detailed)

  • SD2x-3.4 14

    UML Class Diagram (Detailed)

  • SD2x-3.4 15

    UML Class Diagram (Detailed)

  • SD2x-3.4 16

    UML Class Diagram (Detailed)

  • SD2x-3.4 17

    UML Class Diagram (Detailed)

  • SD2x-3.4 18

    UML Class Diagram (Detailed)

  • SD2x-3.4 19

    UML Class Diagram (Detailed)

  • SD2x-3.4 20

    UML Class Diagram (Detailed)

  • SD2x-3.4 21

    Describes the number of objects that can be used in an association n : exactly n objects * : 0 or more objects m..n : a minimum of m and a maximum of n objects

    Multiplicity

  • SD2x-3.4 22

    In general, do not use aggregation/composition for primitive types, even to represent multiplicity

    To demonstrate multiplicity, use [ ]-notation

    Multiplicity and Attributes

  • SD2x-3.4 23

    UML Class Diagram (Detailed)

  • SD2x-3.4 24

    UML Class Diagram (Detailed)

  • SD2x-3.4 25

    UML Class Diagram (Detailed)

  • SD2x-3.4 26

    UML Class Diagram (Detailed)

  • SD2x-3.4 27

    UML Class Diagram (Detailed)

  • SD2x-3.4 28

    How do we convert a UML class design into Java?

  • SD2x-3.4 29

    UML Class Diagram (Detailed)

  • SD2x-3.4 30

    public abstract class BankAccount {

    protected double balance;protected String accountId;protected Customer accountOwner;

    // NOT SHOWN: constructors, get/set methods

    public void open(double initialBalance) { . . . }

    public double deposit(double amount) { . . . }

    public double withdraw(double amount) { . . . }

    }

  • SD2x-3.4 31

    public abstract class BankAccount {

    protected double balance;protected String accountId;protected Customer accountOwner;

    // NOT SHOWN: constructors, get/set methods

    public void open(double initialBalance) { . . . }

    public double deposit(double amount) { . . . }

    public double withdraw(double amount) { . . . }

    }

  • SD2x-3.4 32

    public abstract class BankAccount {

    protected double balance;protected String accountId;protected Customer accountOwner;

    // NOT SHOWN: constructors, get/set methods

    public void open(double initialBalance) { . . . }

    public double deposit(double amount) { . . . }

    public double withdraw(double amount) { . . . }

    }

  • SD2x-3.4 33

    public abstract class BankAccount {

    protected double balance;protected String accountId;protected Customer accountOwner;

    // NOT SHOWN: constructors, get/set methods

    public void open(double initialBalance) { . . . }

    public double deposit(double amount) { . . . }

    public double withdraw(double amount) { . . . }

    }

  • SD2x-3.4 34

    public abstract class BankAccount {

    protected double balance;protected String accountId;protected Customer accountOwner;

    // NOT SHOWN: constructors, get/set methods

    public void open(double initialBalance) { . . . }

    public double deposit(double amount) { . . . }

    public double withdraw(double amount) { . . . }

    }

  • SD2x-3.4 35

    UML Class Diagram (Detailed)

  • SD2x-3.4 36

    UML Class Diagram (Detailed)

  • SD2x-3.4 37

    public class SavingsAccount extends BankAccount {

    protected double interestRate;

    // NOT SHOWN: constructors, get/set methods

    public double applyInterest( ) { . . . }

    }

  • SD2x-3.4 38

    public class SavingsAccount extends BankAccount {

    protected double interestRate;

    // NOT SHOWN: constructors, get/set methods

    public double applyInterest( ) { . . . }

    }

  • SD2x-3.4 39

    public class SavingsAccount extends BankAccount {

    protected double interestRate;

    // NOT SHOWN: constructors, get/set methods

    public double applyInterest( ) { . . . }

    }

  • SD2x-3.4 40

    public class SavingsAccount extends BankAccount {

    protected double interestRate;

    // NOT SHOWN: constructors, get/set methods

    public double applyInterest( ) { . . . }

    }

  • SD2x-3.4 41

    UML Class Diagram (Detailed)

  • SD2x-3.4 42

    UML Class Diagram (Detailed)

  • SD2x-3.4 43

    public class Person {

    protected String name;protected String emailAddress;protected Address homeAddress;protected Address workAddress;

    // NOT SHOWN: constructors, get/set methods

    }

    public class Customer extends Person {

    protected String customerId;

    // NOT SHOWN: constructors, get/set methods

    }

  • SD2x-3.4 44

    public class Person {

    protected String name;protected String emailAddress;protected Address homeAddress;protected Address workAddress;

    // NOT SHOWN: constructors, get/set methods

    }

    public class Customer extends Person {

    protected String customerId;

    // NOT SHOWN: constructors, get/set methods

    }

  • SD2x-3.4 45

    public class Person {

    protected String name;protected String emailAddress;protected Address homeAddress;protected Address workAddress;

    // NOT SHOWN: constructors, get/set methods

    }

    public class Customer extends Person {

    protected String customerId;

    // NOT SHOWN: constructors, get/set methods

    }

  • SD2x-3.4 46

    public class Person {

    protected String name;protected String emailAddress;protected Address homeAddress;protected Address workAddress;

    // NOT SHOWN: constructors, get/set methods

    }

    public class Customer extends Person {

    protected String customerId;

    // NOT SHOWN: constructors, get/set methods

    }

  • SD2x-3.4 47

    public class Person {

    protected String name;protected String emailAddress;protected Address homeAddress;protected Address workAddress;

    // NOT SHOWN: constructors, get/set methods

    }

    public class Customer extends Person {

    protected String customerId;

    // NOT SHOWN: constructors, get/set methods

    }

  • SD2x-3.4 48

    public class Person {

    protected String name;protected String emailAddress;protected Address homeAddress;protected Address workAddress;

    // NOT SHOWN: constructors, get/set methods

    }

    public class Customer extends Person {

    protected String customerId;

    // NOT SHOWN: constructors, get/set methods

    }

  • SD2x-3.4 49

    Allow us to show details of classes in our design Fields (attributes) Methods (operations) Named relationships Multiplicity

    Can easily be converted to Java

    Recap: Detailed UML Class Diagrams

  • SD2x-3.5 1Property of Penn Engineering, Chris Murphy

    SD2x3.5

    Software Quality

    Chris

  • SD2x-3.5 2Property of Penn Engineering, Chris Murphy

    Is software getting better?

  • SD2x-3.5 3Property of Penn Engineering, Chris Murphy

    Transcendental: can be recognized but not defined or measured

    User: satisfies end-users needs Manufacturer: conforms to specification

    (regardless of what users want) Product: based on internal characteristics Value-based: depends on what someone is

    willing to pay for it

    Perspectives on Quality

  • SD2x-3.5 4Property of Penn Engineering, Chris Murphy

    McCall: hierarchy of factors, criteria, and metrics (1977)

    ISO 9126: characteristics and sub-characteristics (1991)

    ISO 25010: revision (2011)

    CMU Software Engineering Institute: performance, dependability, safety (1995)

    Quality Models

  • SD2x-3.5 5Property of Penn Engineering, Chris Murphy

    External: executable program running on hardware in some environment

    Internal: code as human-readable text

    A definition of Software Quality

  • SD2x-3.5 6Property of Penn Engineering, Chris Murphy

    Functionality: satisfies stated or implied needs Reliability: maintains a level of performance in a given

    environment for a given period of time Usability: ease with which user can understand, learn,

    and operate the software Efficiency: limits the amount/number of resources

    used Portability: ease with which software can be

    transferred from one environment to another Security: level of confidentiality and integrity provided

    by the software

    External Quality

  • SD2x-3.5 7Property of Penn Engineering, Chris Murphy

    Ease with which a programmer can: understand the code add new functionality modify existing functionality reuse code incorporate new code identify and fix defects modify the code to improve external quality

    Internal Quality: Maintainability

  • SD2x-3.5 8Property of Penn Engineering, Chris Murphy

    Analyzability

    Changeability

    Stability

    Testability

    Internal Quality

  • SD2x-3.5 9Property of Penn Engineering, Chris Murphy

    Ease with which a programmer can read, understand, and reason about the code

    Identify and fix defects Add or improve functionality Understand how an algorithm (solution) is

    implemented Improve other aspects of software quality

    (efficiency, security, etc.)

    Analyzability

  • SD2x-3.5 10Property of Penn Engineering, Chris Murphy

    Ease with which a programmer can changethe code

    Fix defects Add or improve functionality Incorporate new code Improve other aspects of software quality

    (efficiency, security, etc.)

    Changeability

  • SD2x-3.5 11Property of Penn Engineering, Chris Murphy

    Extent to which the code is tolerant of changes to other parts of the code

    Changes in one part of code dont require changes in other parts

    Reduce time/effort required to change code, since you wont also need to change other code

    Stability

  • SD2x-3.5 12Property of Penn Engineering, Chris Murphy

    Ease with which a the code can be tested

    Create test cases Identify and fix defects Increase confidence that software is working

    correctly

    Testability

  • SD2x-3.5 13Property of Penn Engineering, Chris Murphy

  • SD2x-3.6 1Property of Penn Engineering, Chris Murphy

    SD2x3.6

    Software Design Concepts

    Chris

  • SD2x-3.6 2Property of Penn Engineering, Chris Murphy

    RequirementsRequirementsRequirementsRequirements

    AnalyzabilityChangeability

    StabilityTestability

    ???

  • SD2x-3.6 3Property of Penn Engineering, Chris Murphy

    1. Modeling: identify concepts and their relationships

    2. Choose the right architecture

    3. Create/Use appropriate data structures

    4. Use design patterns when appropriate

    5. Refactor (change the design) as necessary

    How do we design software?

  • SD2x-3.6 4Property of Penn Engineering, Chris Murphy

    1. Modeling: identify concepts and their relationships

    2. Choose the right architecture

    3. Create/Use appropriate data structures

    4. Use design patterns when appropriate

    5. Refactor (change the design) as necessary

    How do we design software?

  • SD2x-3.6 5Property of Penn Engineering, Chris Murphy

    Design a Java program that reads a file containing info about courses, instructors, and enrollment

    And then allows the user to choose to see either: the instructor(s) for a given course the average enrollment for the course

    Motivating Example

  • SD2x-3.6 7Property of Penn Engineering, Chris Murphy

    A single piece of code (main method) that: Reads the data from the file and puts it into a

    data structure

    Prompts the user for the operation to perform (show instructors for a course, or show average enrollment for a course)

    Prompts the user to enter the course number

    Performs the operation and handles errors accordingly

    Shows the results to the user

    The Monolith!

  • SD2x-3.6 8Property of Penn Engineering, Chris Murphy

    Whats wrong with the Monolith?

  • SD2x-3.6 9Property of Penn Engineering, Chris Murphy

    analyzability: main method can be fairly long changeability: hard to find the code you want

    to change stability: hard to know whether a change in

    one place will affect other places testability: if something goes wrong, hard to

    find the bug hard to reuse any of the code

    Whats wrong with the Monolith?

  • SD2x-3.6 10Property of Penn Engineering, Chris Murphy

    How can we address these problems?

  • SD2x-3.6 11Property of Penn Engineering, Chris Murphy

    Divide system into subsystems (components, or combinations of components) that address major features

    Each subsystem should be able to do its work with minimal dependency on other subsystems

    Examples:

    Model-View-Controller (MVC)

    Software as a Service (SaaS)

    N-Tier

    High-level design (Architecture)

  • SD2x-3.6 12Property of Penn Engineering, Chris Murphy

    Presentation Get input from user.Display output.

    Three-Tier Architecture

  • SD2x-3.6 13Property of Penn Engineering, Chris Murphy

    Presentation

    Logic

    Get input from user.Display output.

    Perform calculations.Make decisions.

    Three-Tier Architecture

  • SD2x-3.6 14Property of Penn Engineering, Chris Murphy

    Presentation

    Logic

    Data

    Get input from user.Display output.

    Perform calculations.Make decisions.

    Store and retrieve data.

    Three-Tier Architecture

  • SD2x-3.6 15Property of Penn Engineering, Chris Murphy

    Presentation

    Logic

    Data

    Three-Tier Architecture

    Get input from user.Display output.

    Perform calculations.Make decisions.

    Store and retrieve data.

  • SD2x-3.6 16Property of Penn Engineering, Chris Murphy

    Presentation

    Logic

    Data

    Three-Tier Architecture

    Get input from user.Display output.

    Perform calculations.Make decisions.

    Store and retrieve data.

  • SD2x-3.6 17Property of Penn Engineering, Chris Murphy

    Applying the Three-Tier Architecture

  • SD2x-3.6 18Property of Penn Engineering, Chris Murphy

    Applying the Three-Tier Architecture

  • SD2x-3.6 19Property of Penn Engineering, Chris Murphy

    Applying the Three-Tier Architecture

  • SD2x-3.6 20Property of Penn Engineering, Chris Murphy

    Applying the Three-Tier Architecture

  • SD2x-3.6 21Property of Penn Engineering, Chris Murphy

    analyzability: the program is divided into smaller pieces that are easier to read and understand

    changeability: easier to find the code you want to change; less code to change

    stability: can change one piece without worrying about its effect on others

    testability: easy to test each of these separately

    can reuse different parts of the code

    Why is this better than Monolith?

  • SD2x-3.6 22Property of Penn Engineering, Chris Murphy

    How can we achieve internal quality?

  • SD2x-3.6 23Property of Penn Engineering, Chris Murphy

    Modularity: each component addresses a single part of the functionality

    Functional Independence: components should have minimal dependence on other components

    Abstraction: components should be able to use other components with minimal knowledge of the details of their implementation

    Software Design Concepts

  • SD2x-3.7 1Property of Penn Engineering, Chris Murphy

    SD2x3.7

    Modularity

    Chris

  • SD2x-3.7 2Property of Penn Engineering, Chris Murphy

    Analyzability

    Changeability

    Stability

    Testability

    Internal Quality

  • SD2x-3.7 3Property of Penn Engineering, Chris Murphy

    Modularity

    Functional Independence

    Abstraction

    Software Design Concepts

  • SD2x-3.7 4Property of Penn Engineering, Chris Murphy

    Modularity

    Functional Independence

    Abstraction

    Software Design Concepts

  • SD2x-3.7 5Property of Penn Engineering, Chris Murphy

    Design a Java program that reads a file containing info about courses, instructors, and enrollment

    And then allows the user to choose to see either: the instructor(s) for a given course the average enrollment for the course

    Motivating Example

  • SD2x-3.7 6Property of Penn Engineering, Chris Murphy

    A Modular Design

  • SD2x-3.7 7Property of Penn Engineering, Chris Murphy

    A Modular Design

  • SD2x-3.7 8Property of Penn Engineering, Chris Murphy

    A Modular Design

  • SD2x-3.7 9Property of Penn Engineering, Chris Murphy

    A Modular Design

  • SD2x-3.7 10Property of Penn Engineering, Chris Murphy

    Each component (module) addresses a single part of the functionality

    In Java, this is often accomplished simply by creating separate classes

    Single Responsibility Principle: a class should only have one reason to change

    Modularity: Separation of Concerns

  • SD2x-3.7 11Property of Penn Engineering, Chris Murphy

    Analyzability: leads to smaller pieces of code, each of which is easier to understand

    Testability: permits testing of individual pieces; easier to find and fix bugs

    Reusability: pieces of code can be reused in this application or in other applications

    Changeability: easy to find code that needs to be changed (and then change it!)

    Why Modularity?

  • SD2x-3.7 12Property of Penn Engineering, Chris Murphy

    What could change?

  • SD2x-3.7 13Property of Penn Engineering, Chris Murphy

    What could change?

  • SD2x-3.7 14Property of Penn Engineering, Chris Murphy

    (Human) language used in UI Prompts for input Mechanism for input Format of output UI technology: command line, Swing, Android How error messages are displayed

    What could change? User Interface

  • SD2x-3.7 15Property of Penn Engineering, Chris Murphy

    What could change?

  • SD2x-3.7 16Property of Penn Engineering, Chris Murphy

    What were searching Logic of conducting the search Details of the search, e.g. whether its case-

    sensitive How errors are handled

    What could change? Processor

  • SD2x-3.7 17Property of Penn Engineering, Chris Murphy

    What could change?

  • SD2x-3.7 18Property of Penn Engineering, Chris Murphy

    Format of input: CSV, JSON, XML, etc. Layout of format: ordering of fields Source of input: file, database, web service How errors are handled

    What could change? FileReader

  • SD2x-3.7 19Property of Penn Engineering, Chris Murphy

    Design a program that reads in a file containing tweets, which include text and geolocation info

    Determine the most popular hashtag for a given U.S. state

    Another Motivating Example

  • SD2x-3.7 20Property of Penn Engineering, Chris Murphy

    A modular design

  • SD2x-3.7 21Property of Penn Engineering, Chris Murphy

    A modular design

  • SD2x-3.7 22Property of Penn Engineering, Chris Murphy

    A modular design

  • SD2x-3.7 23Property of Penn Engineering, Chris Murphy

    A modular design

  • SD2x-3.7 24Property of Penn Engineering, Chris Murphy

    A modular design

  • SD2x-3.7 25Property of Penn Engineering, Chris Murphy

    A more modular design

  • SD2x-3.7 26Property of Penn Engineering, Chris Murphy

    A more modular design

  • SD2x-3.7 27Property of Penn Engineering, Chris Murphy

    A more modular design

  • SD2x-3.7 28Property of Penn Engineering, Chris Murphy

    A more modular design

  • SD2x-3.7 29Property of Penn Engineering, Chris Murphy

    An even more modular design

  • SD2x-3.7 30Property of Penn Engineering, Chris Murphy

    An even more modular design

  • SD2x-3.7 31Property of Penn Engineering, Chris Murphy

    An even more modular design

  • SD2x-3.7 32Property of Penn Engineering, Chris Murphy

    The extent to which the parts of a module (class) go together

    All operations and attributes should contribute to a single, well-defined task

    Cohesion

  • SD2x-3.7 33Property of Penn Engineering, Chris Murphy

    Is this cohesive?

  • SD2x-3.7 34Property of Penn Engineering, Chris Murphy

    Is this cohesive?

  • SD2x-3.7 35Property of Penn Engineering, Chris Murphy

    Is this too much modularity?

  • SD2x-3.7 36Property of Penn Engineering, Chris Murphy

    Is this too much modularity?

  • SD2x-3.7 37Property of Penn Engineering, Chris Murphy

    Is this too much modularity?

  • SD2x-3.7 38Property of Penn Engineering, Chris Murphy

    A cohesive, modular design

  • SD2x-3.7 39Property of Penn Engineering, Chris Murphy

    Each component (module) addresses a single part of the functionality

    Improves analyzability, testability, and changeability

    Cohesion: the extent to which the parts of a module go together

    Recap: Modularity

  • SD2x-3.8 1Property of Penn Engineering, Chris Murphy

    SD2x3.8

    Functional Independence

    Chris

  • SD2x-3.8 2Property of Penn Engineering, Chris Murphy

    Modularity

    Functional Independence

    Abstraction

    Software Design Concepts

  • SD2x-3.8 3Property of Penn Engineering, Chris Murphy

    Modularity

    Functional Independence

    Abstraction

    Software Design Concepts

  • SD2x-3.8 4Property of Penn Engineering, Chris Murphy

    Design a program that reads in a file containing tweets, which include text and geolocation info

    Determine the most popular hashtag for a given U.S. state

    Motivating Example

  • SD2x-3.8 5Property of Penn Engineering, Chris Murphy

    A Modular Design

  • SD2x-3.8 6Property of Penn Engineering, Chris Murphy

    A Modular Design

  • SD2x-3.8 7Property of Penn Engineering, Chris Murphy

    A Modular Design

  • SD2x-3.8 8Property of Penn Engineering, Chris Murphy

    A Modular Design

  • SD2x-3.8 9Property of Penn Engineering, Chris Murphy

    A module should be able to do its work with minimal dependence on other modules

    Try to minimize the number and complexity of interfaces between modules

    Functional Independence

  • SD2x-3.8 10Property of Penn Engineering, Chris Murphy

    Analyzability: easier to understand a module without having to look at other code

    Testability: permits testing of a module independent from other modules

    Reusability: pieces of code can be reused without need their dependencies

    Changeability/Stability: can change code without needing to change the things that depend on it

    Why Functional Independence?

  • SD2x-3.8 11Property of Penn Engineering, Chris Murphy

    Are these modules independent?

  • SD2x-3.8 12Property of Penn Engineering, Chris Murphy

    Cyclic Dependencies: BAD!

  • SD2x-3.8 13Property of Penn Engineering, Chris Murphy

    Cyclic Dependencies: BAD!

  • SD2x-3.8 14Property of Penn Engineering, Chris Murphy

    Cyclic Dependencies: BAD!

  • SD2x-3.8 15Property of Penn Engineering, Chris Murphy

    Cyclic Dependencies: BAD!

  • SD2x-3.8 16Property of Penn Engineering, Chris Murphy

    public class TweetProcessor {protected StateFinder stateFinder;protected StateFileReader stateFileReader;

    public TweetProcessor() {stateFinder = new StateFinder();stateFileReader = new StateFileReader();stateFinder.setStateReader(stateFileReader);stateFileReader.getAllStates(stateFinder);

    }

    . . .

    }

  • SD2x-3.8 17Property of Penn Engineering, Chris Murphy

    public class TweetProcessor {protected StateFinder stateFinder;protected StateFileReader stateFileReader;

    public TweetProcessor() {stateFinder = new StateFinder();stateFileReader = new StateFileReader();stateFinder.setStateReader(stateFileReader);stateFileReader.getAllStates(stateFinder);

    }

    . . .

    }

  • SD2x-3.8 18Property of Penn Engineering, Chris Murphy

    public class TweetProcessor {protected StateFinder stateFinder;protected StateFileReader stateFileReader;

    public TweetProcessor() {stateFinder = new StateFinder();stateFileReader = new StateFileReader();stateFinder.setStateReader(stateFileReader);stateFileReader.getAllStates(stateFinder);

    }

    . . .

    }

  • SD2x-3.8 19Property of Penn Engineering, Chris Murphy

    public class TweetProcessor {protected StateFinder stateFinder;protected StateFileReader stateFileReader;

    public TweetProcessor() {stateFinder = new StateFinder();stateFileReader = new StateFileReader();stateFinder.setStateReader(stateFileReader);stateFileReader.getAllStates(stateFinder);

    }

    . . .

    }

  • SD2x-3.8 20Property of Penn Engineering, Chris Murphy

    public class TweetProcessor {protected StateFinder stateFinder;protected StateFileReader stateFileReader;

    public TweetProcessor() {stateFinder = new StateFinder();stateFileReader = new StateFileReader();stateFinder.setStateReader(stateFileReader);stateFileReader.getAllStates(stateFinder);

    }

    . . .

    }

  • SD2x-3.8 21Property of Penn Engineering, Chris Murphy

    public class TweetProcessor {protected StateFinder stateFinder;protected StateFileReader stateFileReader;

    public TweetProcessor() {stateFinder = new StateFinder();stateFileReader = new StateFileReader();stateFinder.setStateReader(stateFileReader);stateFileReader.getAllStates(stateFinder);

    }

    . . .

    }

    public class StateFileReader {

    public void getAllStates(StateFinder finder) {State[] states = . . .finder.allStates = states;

    }

    . . .}

  • SD2x-3.8 22Property of Penn Engineering, Chris Murphy

    public class TweetProcessor {protected StateFinder stateFinder;protected StateFileReader stateFileReader;

    public TweetProcessor() {stateFinder = new StateFinder();stateFileReader = new StateFileReader();stateFinder.setStateReader(stateFileReader);stateFileReader.getAllStates(stateFinder);

    }

    . . .

    }

    public class StateFileReader {

    public void getAllStates(StateFinder finder) {State[] states = . . .finder.allStates = states;

    }

    . . .}

  • SD2x-3.8 23Property of Penn Engineering, Chris Murphy

    Coupling

  • SD2x-3.8 24Property of Penn Engineering, Chris Murphy

    Extent to which one module depends on another

    Loose coupling one module depends on another depends only on the data/functionality it requires and

    nothing more

    Tight coupling modules depend on each other modules depend on more data/functionality than is

    minimally required

    Coupling

  • SD2x-3.8 25Property of Penn Engineering, Chris Murphy

    Tight Coupling: BAD!

  • SD2x-3.8 26Property of Penn Engineering, Chris Murphy

    Remove Coupling: GOOD!

  • SD2x-3.8 27Property of Penn Engineering, Chris Murphy

    Remove Coupling: GOOD!

  • SD2x-3.8 28Property of Penn Engineering, Chris Murphy

    Remove Coupling: GOOD!

  • SD2x-3.8 29Property of Penn Engineering, Chris Murphy

    public class TweetProcessor {protected StateFinder stateFinder;protected StateFileReader stateFileReader;

    public TweetProcessor() {stateFinder = new StateFinder();stateFileReader = new StateFileReader();stateFinder.setStateReader(stateFileReader);stateFileReader.getAllStates(stateFinder);

    }

    . . .

    }

  • SD2x-3.8 30Property of Penn Engineering, Chris Murphy

    public class TweetProcessor {protected StateFinder stateFinder;protected StateFileReader stateFileReader;

    public TweetProcessor() {stateFinder = new StateFinder();stateFileReader = new StateFileReader();stateFinder.setStateReader(stateFileReader);stateFileReader.getAllStates(stateFinder);

    }

    . . .

    }

  • SD2x-3.8 31Property of Penn Engineering, Chris Murphy

    public class TweetProcessor {protected StateFinder stateFinder;

    public TweetProcessor() {stateFinder = new StateFinder();

    }. . .

    }

  • SD2x-3.8 32Property of Penn Engineering, Chris Murphy

    public class TweetProcessor {protected StateFinder stateFinder;

    public TweetProcessor() {stateFinder = new StateFinder();

    }. . .

    }

  • SD2x-3.8 33Property of Penn Engineering, Chris Murphy

    public class StateFinder {

    protected State[] allStates;protected StateFileReader stateReader;

    public StateFinder() {stateReader = new StateFileReader();allStates = stateReader.getAllStates();

    }

    . . .}

    public class TweetProcessor {protected StateFinder stateFinder;

    public TweetProcessor() {stateFinder = new StateFinder();

    }. . .

    }

  • SD2x-3.8 34Property of Penn Engineering, Chris Murphy

    public class StateFinder {

    protected State[] allStates;protected StateFileReader stateReader;

    public StateFinder() {stateReader = new StateFileReader();allStates = stateReader.getAllStates();

    }

    . . .}

    public class TweetProcessor {protected StateFinder stateFinder;

    public TweetProcessor() {stateFinder = new StateFinder();

    }. . .

    }

  • SD2x-3.8 35Property of Penn Engineering, Chris Murphy

    Modules should be self-contained

  • SD2x-3.8 36Property of Penn Engineering, Chris Murphy

    Modules should be self-contained

  • SD2x-3.8 37Property of Penn Engineering, Chris Murphy

    Modules should be self-contained

  • SD2x-3.8 38Property of Penn Engineering, Chris Murphy

    Simplify dependencies

  • SD2x-3.8 39Property of Penn Engineering, Chris Murphy

    Simplify dependencies

  • SD2x-3.8 40Property of Penn Engineering, Chris Murphy

    Simplify dependencies

  • SD2x-3.8 41Property of Penn Engineering, Chris Murphy

    Simplify dependencies

  • SD2x-3.8 42Property of Penn Engineering, Chris Murphy

    Simplify dependencies

  • SD2x-3.8 43Property of Penn Engineering, Chris Murphy

    Simplify dependencies

  • SD2x-3.8 44Property of Penn Engineering, Chris Murphy

    Simplify dependencies

  • SD2x-3.8 45Property of Penn Engineering, Chris Murphy

    Simplify dependencies

  • SD2x-3.8 46Property of Penn Engineering, Chris Murphy

    Simplify dependencies

  • SD2x-3.8 47Property of Penn Engineering, Chris Murphy

    Simplify dependencies

  • SD2x-3.8 48Property of Penn Engineering, Chris Murphy

    A functionally independent design

  • SD2x-3.8 49Property of Penn Engineering, Chris Murphy

    A module should be able to do its work with minimal dependence on other modules

    Avoid tight coupling (cyclic dependencies) Let modules be self-contained Simplify dependencies

    Recap: Functional Independence

  • SD2x-3.9 1Property of Penn Engineering, Chris Murphy

    SD2x3.9

    Abstraction

    Chris

  • SD2x-3.9 2Property of Penn Engineering, Chris Murphy

    Modularity

    Functional Independence

    Abstraction

    Software Design Concepts

  • SD2x-3.9 3Property of Penn Engineering, Chris Murphy

    Modularity

    Functional Independence

    Abstraction

    Software Design Concepts

  • SD2x-3.9 4Property of Penn Engineering, Chris Murphy

    Design a Java program that reads a file containing info about courses, instructors, and enrollment

    And then allows the user to choose to see either: the instructor(s) for a given course the average enrollment for the course

    Motivating Example

  • SD2x-3.9 5Property of Penn Engineering, Chris Murphy

    A Modular Design

  • SD2x-3.9 6Property of Penn Engineering, Chris Murphy

    A Modular Design

  • SD2x-3.9 7Property of Penn Engineering, Chris Murphy

    A Modular Design

  • SD2x-3.9 8Property of Penn Engineering, Chris Murphy

    A Modular Design

  • SD2x-3.9 9Property of Penn Engineering, Chris Murphy

    A module can use other modules with minimal knowledge of the details of their implementation

    Should only care what they do (services they provide) and not how they do it

    Program to an interface, not an implementation

    Abstraction

  • SD2x-3.9 10Property of Penn Engineering, Chris Murphy

    Stability: can change a modules implementation details with no changes required to modules that depend on it

    Reusability: a module can be reused if it doesnt need to know the details of the things on which it depends

    Why abstraction?

  • SD2x-3.9 11Property of Penn Engineering, Chris Murphy

    How can we improve abstraction?

  • SD2x-3.9 12Property of Penn Engineering, Chris Murphy

    How can we improve abstraction?

  • SD2x-3.9 13Property of Penn Engineering, Chris Murphy

    A more abstract design

  • SD2x-3.9 14Property of Penn Engineering, Chris Murphy

    A more abstract design

  • SD2x-3.9 15Property of Penn Engineering, Chris Murphy

    A more abstract design

  • SD2x-3.9 16Property of Penn Engineering, Chris Murphy

    CourseEvalProcessor shouldnt care or know that the Reader reads from a file, e.g. specifying file name catching file I/O exceptions accessing the File or InputStream object calling methods in Reader like openFile

    Reader should be designed in such a way that its implementation can change without changing its interface

    Abstraction for the Reader class

  • SD2x-3.9 17Property of Penn Engineering, Chris Murphy

    How can we further improve abstraction?

  • SD2x-3.9 18Property of Penn Engineering, Chris Murphy

    How can we further improve abstraction?

  • SD2x-3.9 19Property of Penn Engineering, Chris Murphy

    Use custom classes as needed

  • SD2x-3.9 20Property of Penn Engineering, Chris Murphy

    Use custom classes as needed

  • SD2x-3.9 21Property of Penn Engineering, Chris Murphy

    Use custom classes as needed

  • SD2x-3.9 22Property of Penn Engineering, Chris Murphy

    Use custom classes as needed

  • SD2x-3.9 23Property of Penn Engineering, Chris Murphy

    Use abstract data types classes as needed

  • SD2x-3.9 24Property of Penn Engineering, Chris Murphy

    Use abstract data types classes as needed

  • SD2x-3.9 25Property of Penn Engineering, Chris Murphy

    Use abstract data types classes as needed

  • SD2x-3.9 26Property of Penn Engineering, Chris Murphy

    Use abstract data types classes as needed

  • SD2x-3.9 27Property of Penn Engineering, Chris Murphy

    Use abstract data types classes as needed

  • SD2x-3.9 28Property of Penn Engineering, Chris Murphy

    Interfaces: a class can have a dependency (field, parameter) on an interface without needing to know which class implements it

    Abstract Data Types: Set, List, Map, etc. in the Java Collections API

    Design Patterns: Observer

    Abstraction in the Java API

  • SD2x-3.9 29Property of Penn Engineering, Chris Murphy

    A module can use other modules with minimal knowledge of the details of their implementation

    Should only care what they do (services they provide) and not how they do it

    Program to an interface, not an implementation

    Use custom classes as needed Use abstract data types when possible

    Recap: Abstraction

  • SD2x-3.10 1Property of Penn Engineering, Chris Murphy

    SD2x3.10

    Law of Demeter

    Chris

  • SD2x-3.10 2Property of Penn Engineering, Chris Murphy

    Modularity

    Functional Independence

    Abstraction

    Software Design Concepts

  • SD2x-3.10 3Property of Penn Engineering, Chris Murphy

    Modularity

    Functional Independence

    Abstraction

    Software Design Concepts

  • SD2x-3.10 4Property of Penn Engineering, Chris Murphy

    A module can use other modules with minimal knowledge of the details of their implementation

    Should only care what they do (services they provide) and not how they do it

    Abstraction

  • SD2x-3.10 5Property of Penn Engineering, Chris Murphy

  • SD2x-3.10 6Property of Penn Engineering, Chris Murphy

    public class Game {

    . . .

    protected void updatePlayer(Player player) {

    . . .

    player.getPaintbrush().setColor(Color.RED);

    . . .

  • SD2x-3.10 7Property of Penn Engineering, Chris Murphy

    public class Game {

    . . .

    protected void updatePlayer(Player player) {

    . . .

    player.getPaintbrush().setColor(Color.RED);

    . . .

  • SD2x-3.10 8Property of Penn Engineering, Chris Murphy

    public class Game {

    . . .

    protected void updatePlayer(Player player) {

    . . .

    player.getPaintbrush().setColor(Color.RED);

    . . .

  • SD2x-3.10 9Property of Penn Engineering, Chris Murphy

    public class Game {

    . . .

    protected void updatePlayer(Player player) {

    . . .

    player.getPaintbrush().setColor(Color.RED);

    . . .

  • SD2x-3.10 10Property of Penn Engineering, Chris Murphy

    Also known as the Principle of Least Knowledge Named after the Greek goddess of agriculture

    Law of Demeter

    A module should be able to perform its tasks with (minimal) knowledge of related modules, and with no knowledge of the modules related to those

    Dont talk to strangers

  • SD2x-3.10 11Property of Penn Engineering, Chris Murphy

    A method M in object O may only invoke methods on the following: the object O itself parameters to M objects created in M Os fields global variables

    Law of Demeter

  • SD2x-3.10 12Property of Penn Engineering, Chris Murphy

    public class Game {

    . . .

    protected void updatePlayer(Player player) {

    . . .

    player.getPaintbrush().setColor(Color.RED);

    . . .

  • SD2x-3.10 13Property of Penn Engineering, Chris Murphy

    public class Game {

    . . .

    protected void updatePlayer(Player player) {

    . . .

    player.getPaintbrush().setColor(Color.RED);

    . . .

  • SD2x-3.10 14Property of Penn Engineering, Chris Murphy

    public class Game {

    . . .

    protected void updatePlayer(Player player) {

    . . .

    player.getPaintbrush().setColor(Color.RED);

    . . .

  • SD2x-3.10 15Property of Penn Engineering, Chris Murphy

    public class Game {

    . . .

    protected void updatePlayer(Player player) {

    . . .

    player.getPaintbrush().setColor(Color.RED);

    . . .

  • SD2x-3.10 16Property of Penn Engineering, Chris Murphy

    public class Game {

    . . .

    protected void updatePlayer(Player player) {

    . . .

    Paintbrush brush = player.getPaintbrush();brush.setColor(Color.RED);. . .

  • SD2x-3.10 17Property of Penn Engineering, Chris Murphy

    public class Game {

    . . .

    protected void updatePlayer(Player player) {

    . . .

    Paintbrush brush = player.getPaintbrush();brush.setColor(Color.RED);. . .

  • SD2x-3.10 18Property of Penn Engineering, Chris Murphy

    public class Game {

    . . .

    protected void updatePlayer(Player player) {

    . . .

    Paintbrush brush = player.getPaintbrush();brush.setColor(Color.RED);. . .

  • SD2x-3.10 19Property of Penn Engineering, Chris Murphy

    public class Game {

    . . .

    protected void updatePlayer(Player player) {

    . . .

    player.getPaintbrush().setColor(Color.RED);

    . . .

  • SD2x-3.10 20Property of Penn Engineering, Chris Murphy

    public class Game {

    . . .

    protected void updatePlayer(Player player) {

    . . .

    player.getPaintbrush().setColor(Color.RED);

    . . .

  • SD2x-3.10 21Property of Penn Engineering, Chris Murphy

    public class Game {

    . . .

    protected void updatePlayer(Player player) {

    . . .

    player.getPaintbrush().setColor(Color.RED);

    . . .

  • SD2x-3.10 22Property of Penn Engineering, Chris Murphy

    Solution:Hide Delegate

  • SD2x-3.10 23Property of Penn Engineering, Chris Murphy

  • SD2x-3.10 24Property of Penn Engineering, Chris Murphy

  • SD2x-3.10 25Property of Penn Engineering, Chris Murphy

  • SD2x-3.10 26Property of Penn Engineering, Chris Murphy

    public class Player {. . .private Paintbrush paintbrush;public void setColor(Color color) {

    paintbrush.setColor(color);}. . .

    }

  • SD2x-3.10 27Property of Penn Engineering, Chris Murphy

    public class Player {. . .private Paintbrush paintbrush;public void setColor(Color color) {

    paintbrush.setColor(color);}. . .

    }

  • SD2x-3.10 28Property of Penn Engineering, Chris Murphy

    public class Player {. . .private Paintbrush paintbrush;public void setColor(Color color) {

    paintbrush.setColor(color);}. . .

    }

  • SD2x-3.10 29Property of Penn Engineering, Chris Murphy

    public class Game {. . .

    protected void updatePlayer(Player player) {. . .

    player.getPaintbrush().setColor(Color.RED);

    . . .

    public class Player {. . .private Paintbrush paintbrush;public void setColor(Color color) {

    paintbrush.setColor(color);}. . .

    }

  • SD2x-3.10 30Property of Penn Engineering, Chris Murphy

    public class Game {. . .

    protected void updatePlayer(Player player) {. . .

    player.getPaintbrush().setColor(Color.RED);

    . . .

    public class Player {. . .private Paintbrush paintbrush;public void setColor(Color color) {

    paintbrush.setColor(color);}. . .

    }

  • SD2x-3.10 31Property of Penn Engineering, Chris Murphy

    public class Game {. . .

    protected void updatePlayer(Player player) {. . .

    player.setColor(Color.RED);

    . . .

    public class Player {. . .private Paintbrush paintbrush;public void setColor(Color color) {

    paintbrush.setColor(color);}. . .

    }

  • SD2x-3.10 32Property of Penn Engineering, Chris Murphy

    public class Game {. . .

    protected void updatePlayer(Player player) {. . .

    player.setColor(Color.RED);

    . . .

    public class Player {. . .private Paintbrush paintbrush;public void setColor(Color color) {

    paintbrush.setColor(color);}. . .

    }

  • SD2x-3.10 33Property of Penn Engineering, Chris Murphy

    public class Game {. . .

    protected void updatePlayer(Player player) {. . .

    player.setColor(Color.RED);

    . . .

    public class Player {. . .private Paintbrush paintbrush;public void setColor(Color color) {

    paintbrush.setColor(color);}. . .

    }

  • SD2x-3.10 34Property of Penn Engineering, Chris Murphy

    public class Game {. . .

    protected void updatePlayer(Player player) {. . .

    player.setColor(Color.RED);

    . . .

    public class Player {. . .private Paintbrush paintbrush;public void setColor(Color color) {

    paintbrush.alterColor(color);}. . .

    }

  • SD2x-3.10 35Property of Penn Engineering, Chris Murphy

    Try to avoid Message Chains in your code

    Be careful about violating the Law of Demeter

    Use the Hide Delegate pattern

    This will help improve abstraction

    Recap

  • SD2x-3.10 36Property of Penn Engineering, Chris Murphy

    Internal Quality: Changeability, Stability, Analyzability, Testability

    Design Concepts: Modularity, Functional Independence, Abstraction

    Recap: Software Design

    SD2x3.1_v2_PDFSlide Number 1Slide Number 2Slide Number 3Slide Number 4Slide Number 5Slide Number 6Slide Number 7Slide Number 8Slide Number 9Slide Number 10Slide Number 11

    SD2x3.2_v2_PDFSlide Number 1Slide Number 2Slide Number 3Slide Number 4Slide Number 5Slide Number 6Slide Number 7Slide Number 8Slide Number 9Slide Number 10Slide Number 11Slide Number 12Slide Number 13Slide Number 14Slide Number 15Slide Number 16Slide Number 17

    SD2x3.3_v2_PDFSlide Number 1Slide Number 2Slide Number 3Slide Number 4Slide Number 5Slide Number 6Slide Number 7Slide Number 8Slide Number 9Slide Number 10Slide Number 11Slide Number 12Slide Number 13Slide Number 14Slide Number 15Slide Number 16

    SD2x3.4_v2_PDFSlide Number 1Slide Number 2Slide Number 3Slide Number 4Slide Number 5Slide Number 6Slide Number 7Slide Number 8Slide Number 9Slide Number 10Slide Number 11Slide Number 12Slide Number 13Slide Number 14Slide Number 15Slide Number 16Slide Number 17Slide Number 18Slide Number 19Slide Number 20Slide Number 21Slide Number 22Slide Number 23Slide Number 24Slide Number 25Slide Number 26Slide Number 27Slide Number 28Slide Number 29Slide Number 30Slide Number 31Slide Number 32Slide Number 33Slide Number 34Slide Number 35Slide Number 36Slide Number 37Slide Number 38Slide Number 39Slide Number 40Slide Number 41Slide Number 42Slide Number 43Slide Number 44Slide Number 45Slide Number 46Slide Number 47Slide Number 48Slide Number 49

    SD2x3.5_v2_PDFSlide Number 1Slide Number 2Slide Number 3Slide Number 4Slide Number 5Slide Number 6Slide Number 7Slide Number 8Slide Number 9Slide Number 10Slide Number 11Slide Number 12Slide Number 13

    SD2x3.6_v2_PDFSlide Number 1Slide Number 2Slide Number 3Slide Number 4Slide Number 5Slide Number 7Slide Number 8Slide Number 9Slide Number 10Slide Number 11Slide Number 12Slide Number 13Slide Number 14Slide Number 15Slide Number 16Slide Number 17Slide Number 18Slide Number 19Slide Number 20Slide Number 21Slide Number 22Slide Number 23

    SD2x3.7_v2_PDFSlide Number 1Slide Number 2Slide Number 3Slide Number 4Slide Number 5Slide Number 6Slide Number 7Slide Number 8Slide Number 9Slide Number 10Slide Number 11Slide Number 12Slide Number 13Slide Number 14Slide Number 15Slide Number 16Slide Number 17Slide Number 18Slide Number 19Slide Number 20Slide Number 21Slide Number 22Slide Number 23Slide Number 24Slide Number 25Slide Number 26Slide Number 27Slide Number 28Slide Number 29Slide Number 30Slide Number 31Slide Number 32Slide Number 33Slide Number 34Slide Number 35Slide Number 36Slide Number 37Slide Number 38Slide Number 39

    SD2x3.8_v2_PDFSlide Number 1Slide Number 2Slide Number 3Slide Number 4Slide Number 5Slide Number 6Slide Number 7Slide Number 8Slide Number 9Slide Number 10Slide Number 11Slide Number 12Slide Number 13Slide Number 14Slide Number 15Slide Number 16Slide Number 17Slide Number 18Slide Number 19Slide Number 20Slide Number 21Slide Number 22Slide Number 23Slide Number 24Slide Number 25Slide Number 26Slide Number 27Slide Number 28Slide Number 29Slide Number 30Slide Number 31Slide Number 32Slide Number 33Slide Number 34Slide Number 35Slide Number 36Slide Number 37Slide Number 38Slide Number 39Slide Number 40Slide Number 41Slide Number 42Slide Number 43Slide Number 44Slide Number 45Slide Number 46Slide Number 47Slide Number 48Slide Number 49

    SD2x3.9_v2_PDFSlide Number 1Slide Number 2Slide Number 3Slide Number 4Slide Number 5Slide Number 6Slide Number 7Slide Number 8Slide Number 9Slide Number 10Slide Number 11Slide Number 12Slide Number 13Slide Number 14Slide Number 15Slide Number 16Slide Number 17Slide Number 18Slide Number 19Slide Number 20Slide Number 21Slide Number 22Slide Number 23Slide Number 24Slide Number 25Slide Number 26Slide Number 27Slide Number 28Slide Number 29

    SD2x3.10_v2_PDFSlide Number 1Slide Number 2Slide Number 3Slide Number 4Slide Number 5Slide Number 6Slide Number 7Slide Number 8Slide Number 9Slide Number 10Slide Number 11Slide Number 12Slide Number 13Slide Number 14Slide Number 15Slide Number 16Slide Number 17Slide Number 18Slide Number 19Slide Number 20Slide Number 21Slide Number 22Slide Number 23Slide Number 24Slide Number 25Slide Number 26Slide Number 27Slide Number 28Slide Number 29Slide Number 30Slide Number 31Slide Number 32Slide Number 33Slide Number 34Slide Number 35Slide Number 36