1 / 35

Chapter 6 Object-Oriented Software Design and Implementation

Chapter 6 Object-Oriented Software Design and Implementation. Chapter 6 Topics. Software Design Strategies Objects and Classes Revisited Object-Oriented Design The CRC Card Design Process Functional Decomposition Object-Oriented Implementation Packages

hagan
Télécharger la présentation

Chapter 6 Object-Oriented Software Design and Implementation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 6 Object-Oriented Software Design and Implementation

  2. Chapter 6 Topics • Software Design Strategies • Objects and Classes Revisited • Object-Oriented Design • The CRC Card Design Process • Functional Decomposition • Object-Oriented Implementation • Packages • Ethics and Responsibility in the Computing Profession

  3. Software Design Strategies FUNCTIONALOBJECT-ORIENTED DECOMPOSITIONDESIGN The problem is divided into more easily handled subproblems, the solutions of which together create a solution to the overall problem. Produces a hierarchy of tasks. The solution is expressed in terms of objects (self-contained entities composed of data and operations on that data) that interact by sending messages to one another. Produces a hierarchy of objects.

  4. More about OOD • Languages supporting OOD include: Java, Smalltalk, Eiffel, CLOS, and Object-Pascal • A class defines the pattern used when instantiating an object of that type • A class generally contains private data and public operations (called methods)

  5. Object-Oriented Design (OOD) • Focus is on the entities (objects) in a problem • Beginsby identifying the classes of objects in the problem, and choosing appropriate operations on those objects • Programs are collections of objects that communicate with (send messages to) each other • Data plays a leading role; algorithms are used to implement operations on the objects and to enable interaction of objects with each other

  6. OOD good with large software projects • Objects within a program often model real-life objects in the problem to be solved • The OOD concept of inheritance allows the customization of an existing class to meet particular needs. This can reduce the time and effort needed to design, implement, and maintain large systems

  7. Functional Decomposition • A technique for developing a program in which theproblem is divided into more easily handled subproblems,the solutions of which create a solution to the overall problem • In functional decomposition, we work from the abstract (a list of the major solution steps for which some implementation details remain unspecified) to the concrete (algorithmic steps for which the implementation details are fully specified)

  8. Functional Decomposition • Focus is on the sequence of actions (algorithms) required to solve the problem • Begins by breaking the solution into a series of major steps. This process continues until each subproblem cannot be divided further or has an obvious solution • Programs are collections of modules that solve subproblems; a module structure chart (hierarchical solution tree) is often created • Data plays a secondary role in support of actions

  9. Definitions in Functional Decomposition • Concrete step A step for which the implementation details are fully specified • Abstract step A step for which some implementation details remain unspecified • Module A self-contained collection of steps that solves a problem or subprogram; it can contain both concrete and abstract steps

  10. Find Weighted Average Print Weighted Average Module Structure Chart Main Get Data Prepare File for Reading Print Data Print Heading

  11. . . . . . . . . . OBJECT OBJECT FUNCTION FUNCTION FUNCTION Two Design Strategies FUNCTIONALOBJECT-ORIENTED DECOMPOSITION DESIGN OBJECT

  12. Object-Oriented Design Process • Three steps in the process • Identify an initial set of object classes that seem relevant to the problem • nouns often represent objects • verbs often represent actions • Filter the list, eliminating duplicates • Identify the responsibilities for the reduced list of objects

  13. Identify Possible Classes • Brainstorming (by a team) • Identify objects • Propose classes • Write on a blackboard • Keep going around until no one can think of any more objects • No ideas are rejected

  14. Filter List of Possible Classes • Eliminate duplicates • Decide if the classes really do represent objects in the problem • Look for classes that are related • Over looked classes may emerge • For each class that survives the filtering stage, create a CRC card

  15. Blank CRC Card Class Name: Superclass: Subclasses: Responsibilities Collaborations

  16. Definitions • Responsibilities An action that an implementation of an object must be capable of performing • Collaboration An interaction between objects in which one object requests that another object carry out one of its responsibilities

  17. Determine Responsibilities • Initial responsibilities • Know and return the states of the object • Called Knowledge Responsibilities • Action responsibilities Use scenario walk-throughs, a role playing technique, • to explore the actions of a class • to explore the interactions of classes

  18. Address CRC Card Class Name: Superclass: Subclasses: Address Responsibilities Collaborations Create itself None (name, city, state, zip code) Know its name None Know its city None Know its state None Know its zip code None

  19. Name CRC Card Class Name: NameSuperclass: Subclasses: Responsibilities Collaborations Create itself (First, Middle, Last) None Know its first name None Know its middle name None Know its last name None Are two names equal? String Compare two names String

  20. Class Name: NameSuperclass: Subclasses: Responsibilities Collaborations Create itself (First, Middle, Last) None Know its first name None return String Know its middle name None return String Know its last name None return String Are two names equal? String return boolean Compare two names String return int Name CRC Card with Return Types

  21. CRC Card Summary • The use of Classes, Responsibilities and Collaborations (CRC) cards is an informal technique for developing objected-oriented designs • For each class, a CRC card is created listing the class responsibilities and collaborations • Brainstorming, filtering, and scenarios are used to identify and refine the classes and responsibilities needed to solve a problem

  22. Inheritance • Inheritance A mechanism that enables us to define a new class by adapting the definition of an existing class • Example on next slide • Detailed explanation in next Chapter

  23. Address object inheritance hierarchy Object Address HomeAddress CompanyAddress WorkAddress BoxAddress

  24. Categories of Responsibilities • Constructor An operation that creates a new instance of a class • Copy constructor An operation that creates a new instance by copying an existing instance, possibly altering its state in the process • Transformer An operation that changes the state of an object • Observer An operation that allows us to observe the state of an object without changing it • Iterator An operation that allows us to process all the components of an object one at a time

  25. Methods are written to specifications (as on CRC card) • The specifications state the result type, the parameter types, and what task the method is to perform using its parameters • The advantage is that teamwork can occur without knowing what the argument identifiers will actually be

  26. Instance Methods • CRC card responsibilities are implemented as methods in the class • A responsibility that refers to an object should be implemented as an instance method • Constructors, observers, transformers, and iterators are instance methods; they have access to the fields of their associated object, and can receive values through the parameter list

  27. Three Categories of Data • Instance data is the internal representation of a specific object. It records the object’s state. • Class data is accessible to all objects of a class. • Local data is specific to a given call of a method.

  28. Instance Data Instance data is the internal representation of a specific object. public class Name { // Instance variables String first; String middle; String last; . . . }

  29. Class Data • Class data is accessible to all objects of a class. • Fields declared as static belong to the class rather than to a specific instance. public class Name { // Class constant static final String PUNCT = “, ”; . . . }

  30. Local Data • Local data is specific to a given call of a method. • The JVM allocates space for this data when the method is called and deallocates it when the method returns. public int compareTo(Name otherName) { int result; // Local variable . . . return result; }

  31. Package Syntax Compilation Unit packageIdentifier ; ImportDeclaration . . . ClassDeclaration . . .

  32. Package Do’s and Don’t’s • A compilation unit can have only one public class • Many compilation units can be in a package • “No modifier” specifies package access • Any field or method with package access can be accessed by any member of the package

  33. Package Example • package addressBook • Members: • class Address • class Entry • Imported by • class AddressDr • All of the variables have package access

  34. Ethics and Responsibilities • Software piracy The unauthorized copying of software for either personal use or use by others Have you every made unauthorized copies? Has anyone you know done so? Why is it wrong to do so?

  35. More on Ethics • Virus Code that replicates itself, often with the goal of spreading to other computers without authorization, and possibly with the intent of doing harm Has a virus ever attached your machine? Why is creating and/or spreading a virus unethical?

More Related