Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter 6 Object-Oriented Software Design and Implementation.

Similar presentations


Presentation on theme: "1 Chapter 6 Object-Oriented Software Design and Implementation."— Presentation transcript:

1 1 Chapter 6 Object-Oriented Software Design and Implementation

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

3 3 Software Design Strategies FUNCTIONAL OBJECT-ORIENTED DECOMPOSITION DESIGN 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. 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.

4 More about OOD l Languages supporting OOD include: Java, Smalltalk, Eiffel, CLOS, and Object-Pascal l A class defines the pattern used when instantiating an object of that type l 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 Begins by 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 l Objects within a program often model real-life objects in the problem to be solved l 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 lA technique for developing a program in which the problem is divided into more easily handled subproblems, the solutions of which create a solution to the overall problem lIn 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 lFocus is on the sequence of actions (algorithms) required to solve the problem lBegins 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 lPrograms are collections of modules that solve subproblems; a module structure chart (hierarchical solution tree) is often created lData plays a secondary role in support of actions

9 9 Definitions in Functional Decomposition l Concrete step A step for which the implementation details are fully specified l Abstract step A step for which some implementation details remain unspecified l 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 Print Data Print Heading Get Data Prepare File for Reading

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

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

13 13 Identify Possible Classes l Brainstorming (by a team) nIdentify objects nPropose classes nWrite on a blackboard l Keep going around until no one can think of any more objects l No ideas are rejected

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

15 15 Blank CRC Card Class Name: Superclass: Subclasses: ResponsibilitiesCollaborations

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

17 17 Determine Responsibilities l Initial responsibilities nKnow and return the states of the object nCalled Knowledge Responsibilities l Action responsibilities Use scenario walk-throughs, a role playing technique, nto explore the actions of a class nto explore the interactions of classes

18 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 19 Name CRC Card Class Name: Name Superclass: 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 namesString

20 20 Name CRC Card with Return Types Class Name: Name Superclass: 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 namesString return int

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

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

23 23 Address object inheritance hierarchy Object CompanyAddressHomeAddress BoxAddressWorkAddress Address

24 24 Categories of Responsibilities l Constructor An operation that creates a new instance of a class l Copy constructor An operation that creates a new instance by copying an existing instance, possibly altering its state in the process l Transformer An operation that changes the state of an object l Observer An operation that allows us to observe the state of an object without changing it l 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) l The specifications state the result type, the parameter types, and what task the method is to perform using its parameters l The advantage is that teamwork can occur without knowing what the argument identifiers will actually be

26 26 Instance Methods l CRC card responsibilities are implemented as methods in the class l A responsibility that refers to an object should be implemented as an instance method l 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 27 Three Categories of Data l Instance data is the internal representation of a specific object. It records the object’s state. l Class data is accessible to all objects of a class. l 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 l Class data is accessible to all objects of a class. l 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 l Local data is specific to a given call of a method. l 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 31 Package Syntax Compilation Unit package Identifier ; ImportDeclaration... ClassDeclaration...

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

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

34 34 Ethics and Responsibilities l 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 35 More on Ethics l 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?


Download ppt "1 Chapter 6 Object-Oriented Software Design and Implementation."

Similar presentations


Ads by Google