40
Object- Oriented Design Muhammad Adil Raja Introduction Why is OOP Polular? Programming in the Small and in the Large Why Begin With Behavior? A Case Study Components CRC Cards Components and Behavior Preparing for Change Interaction OBJECT-ORIENTED DESIGN Muhammad Adil Raja Roaming Researchers, Inc. cbnd April 9, 2015

Object-Oriented Design

Embed Size (px)

Citation preview

Page 1: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

OBJECT-ORIENTED DESIGN

Muhammad Adil Raja

Roaming Researchers, Inc.

cbnd

April 9, 2015

Page 2: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

OUTLINE I

INTRODUCTION

WHY IS OOP POLULAR?PROGRAMMING IN THE SMALL AND IN THE LARGE

WHY BEGIN WITH BEHAVIOR?A CASE STUDY

COMPONENTS

CRC CARDS

COMPONENTS AND BEHAVIOR

PREPARING FOR CHANGE

INTERACTION DIAGRAMS

SOFTWARE COMPONENTS

FORMALIZE THE INTERFACE

DESIGNING THE REPRESENTATION

IMPLEMENTING COMPONENTS

INTEGRATION OF COMPONENTS

Page 3: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

OUTLINE II

MAINTENANCE AND EVOLUTION

REFERENCES

Page 4: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

INTRODUCTION I

I The most important aspect of OOP is the creation of auniverse of largely autonomous interacting agents.

I How does one come up with such a system?I The answer is a design technique driven by the

determination and delegation of responsibilities.I The technique described in this chapter is termed

responsibility-driven design.

Page 5: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

WHY IS OOP POLULAR? I

I Scalability – from simplest of problems to the mostcomplex.

I Provides and abstraction that resonates withtechniques people use to solve problems in their dailylives.

I Libraries assist in code reusability.I Addresses the software crisis.I Our imaginations and the tasks we would like to solve

with computers outstrips our abilities.I A new paradigm.I Structure for scientific revolutions.I Responsibility implies noninterference.

Page 6: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

PROGRAMMING IN THE SMALL AND IN THE

LARGE I

I Programming in the small characterizes projects withthe following attributes:

I Code is developed by a single programmer, or perhapsby a very small collection of programmers.

I A single individual can understand all aspects of aproject, from top to bottom, beginning to end.

I The major problem in the software developmentprocess is the design and development of algorithms fordealing with the problem at hand.

I Programming in the large, on the other hand,characterizes software projects with features such asthe following:

I The software system is developed by a large team,often consisting of people with many different skills.

I There may be graphic artists, design experts, as well asprogrammers.

Page 7: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

PROGRAMMING IN THE SMALL AND IN THE

LARGE II

I Individuals involved in the speci cation or design of thesystem may differ from those involved in the coding ofindividual components, who may differ as well fromthose involved in the integration of various componentsin the nal product.

I No single individual can be considered responsible forthe entire project, or even necessarily understands allaspects of the project.

I The major problem in the software developmentprocess is the management of details and thecommunication of information between diverse portionsof the project.

Page 8: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

PROGRAMMING IN THE SMALL AND IN THE

LARGE III

I While the beginning student will usually be acquaintedwith programming in the small, aspects of manyobject-oriented languages are best understood asresponses to the problems encountered whileprogramming in the large.

I Some appreciation of the difficulties involved indeveloping large systems is a helpful prerequisite tounderstanding OOP.

Page 9: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

WHY BEGIN WITH BEHAVIOR? I

I Why begin the design process with an analysis ofbehavior?

I The behavior of a system is usually understood longbefore any other aspect.

I Earlier software development methodologies (thosepopular before the ad- vent of object-orientedtechniques) concentrated on ideas such ascharacterizing the basic data structures or the overallstructure of function calls, often within the creation of aformal specification of the desired application.

I But structural elements of the application can beidentified only after a considerable amount of problemanalysis.

Page 10: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

WHY BEGIN WITH BEHAVIOR? II

I Similarly, a formal specification often ended up as adocument understood by neither programmer nor client.

I But behavior is something that can be described almostfrom the moment an idea is conceived, and (oftenunlike a formal specification) can be described in termsmeaningful to both the programmers and the client.

I Responsibility-Driven Design (RDD), developed byRebecca Wirfs-Brock, is an object-oriented designtechnique that is driven by an emphasis on behavior atall levels of development.

I It is but one of many alternative object-oriented designtechniques.

Page 11: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

THE INTERACTIVE KITCHEN HELPER (IIKH) I

SIMPLE BROWSING

Page 12: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

THE INTERACTIVE KITCHEN HELPER (IIKH) II

Alice Smith sits down at her computer and starts the IIKH.When the program begins, it displays a graphical image of arecipe box, and identifies itself as the IIKH, product of IIKHincorporated. Alice presses the return button to begin.In response to the key press, Alice is given a choice of anumber of options. She elects to browse the recipe index,looking for a recipe for Salmon that she wishes to preparefor dinner the next day. She enters the keyword Salmon,and is shown in response a list of various recipes. Sheremembers seeing an interesting recipe that used dill-weedas a avoring. She re nes the search, entering the wordsSalmon and dill-weed. This narrows the search to tworecipes.She selects the first. This brings up a new window in whichan attractive picture of the finished dish is displayed, alongwith the list of ingredients, preparation steps, and expectedpreparation time. After examining the recipe, Alice decides itis not the recipe she had in mind. She returns to the searchresult page, and selects the second alternative.Examining this dish, Alice decides this is the one she had inmind. She requests a printing of the recipe, and the outputis spooled to her printer. Alice selects quit" from a programmenu, and the application quits.

Page 13: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

COMPONENTS I

I The engineering of a complex physical system, such asa building or an auto- mobile engine, is simplified bydividing the design into smaller units.

I So, too, the engineering of software is simplified by theidentification and development of software components.

I A component is simply an abstract entity that canperform tasks that is, fulfill some responsibilities.

I At this point, it is not necessary to know exactly theeventual representation for a component or how acomponent will perform a task.

I A component may ultimately be turned into a function, astructure or class, or a collection of other components.

I At this level of development there are just two importantcharacteristics:

Page 14: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

COMPONENTS II

I A component must have a small well-de ned set ofresponsibilities.

I A component should interact with other components tothe minimal extent possible.

Page 15: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

CRC CARDS I

I Written on the face of the card is the name of thesoftware compo- nent, the responsibilities of thecomponent, and the names of other components withwhich the component must interact.

I Such cards are sometimes known as CRC (Component, Responsibility , Collaborator) cards, and areassociated with each software component.

I The What/Who cycle.I Documentation.I Two documents need to be prepared.

I User’s manual.I System design documentation.

I The user’s manual describes methods for interactionwith the system from the user’s point of view.

Page 16: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

CRC CARDS II

I It should be developed even before the first line of codeis written.

Page 17: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

COMPONENTS AND BEHAVIOR I

I Components of the Greeter.1. Casually browse the database of existing recipes, but

without reference to any particular meal plan.2. Add a new recipe to the database.3. Edit or annotate an existing recipe.4. Review an existing plan for several meals.5. Create a new plan of meals.

I Postponning decisions.

Page 18: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

PREPARING FOR CHANGE I

I Programmers and software designers need toanticipate that changes would inevitably be required.

I The primary objective is that changes should a ect asfew components as possible.

I Even major changes in the appearance or functioningof an application should be possible with alterations toonly one or two sections of code.

I Try to predict the most likely sources of change andisolate the effects of such changes to as few softwarecomponents as possible.

I The most likely sources of change are interfaces,communication formats, and output formats.

I Try to isolate and reduce the dependency of softwareon hardware.

Page 19: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

PREPARING FOR CHANGE II

I For example, the interface for recipe browsing in ourapplication may depend in part on the hardware onwhich the system is running.

I Future releases may be ported to different platforms.I A good design will anticipate this change.I Reducing coupling between software components will

reduce the dependence of one upon another, andincrease the likelihood that one can be changed withminimal e ect on the other.

I In the design documentation maintain careful records ofthe design process and the discussions surrounding allmajor decisions.

Page 20: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

PREPARING FOR CHANGE III

I It is almost certain that the individuals responsible formaintaining the software and designing future releaseswill be at least partially di erent from the teamproducing the initial release.

I The design documentation will allow future teams toknow the important factors behind a decision and helpthem avoid spending time discussing issues that havealready been resolved.

I Continuing the scenario.

Page 21: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

INTERACTION DIAGRAMS I

FIGURE : Interaction Diagram

Page 22: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

SOFTWARE COMPONENTS I

I Behavior and state.I The behavior of a component is the set of actions it can

perform.I The complete description of all the behavior for a

component is sometimes called the protocol.I For the Recipe component this includes activities such

as editing the preparation instructions, displaying therecipe on a terminal screen, or printing a copy of therecipe.

I The state of a component represents all the informationheld within it at a given point of time.

I For our Recipe component the state includes theingredients and preparation instructions.

Page 23: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

SOFTWARE COMPONENTS II

I Notice that the state is not static and can change overtime.

I For example, by editing a recipe (a behavior) the usercan make changes to the preparation instructions (partof the state).

Page 24: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

INSTANCES AND CLASSES I

I The term class is used to describe a set of objects withsimilar behavior.

I We will see in later chapters that a class is also used asa syntactic mechanism in almost all object-orientedlanguages.

I An individual representative of a class is known as aninstance.

I Note that behavior is associated with a class, not withan individual.

I That is, all instances of a class will respond to the sameinstructions and perform in a similar manner.

I On the other hand, state is a property of an individual.I We see this in the various instances of the class

Recipe.

Page 25: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

INSTANCES AND CLASSES II

I They can all perform the same actions (editing,displaying, printing) but use different data values.

Page 26: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

COUPLING AND COHESION I

I Cohesion is the degree to which the responsibilities ofa single component form a meaningful unit.

I High cohesion is achieved by associating in a singlecomponent tasks that are related in some manner.Coupling, on the other hand, describes the relationshipbetween software components.

I In general, it is desirable to reduce the amount ofcoupling as much as possible, since connectionsbetween software components inhibit ease ofdevelopment, modification, or reuse.

I In particular, coupling is increased when one softwarecomponent must access data values the state held byanother component.

Page 27: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

COUPLING AND COHESION II

I Such situations should almost always be avoided infavor of moving a task into the list of responsibilities ofthe component that holds the necessary data.

Page 28: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

INTERFACE AND IMPLEMENTATION – PARNAS’S

PRINCIPLES I

I The developer of a software component must providethe intended user with all the information needed tomake e ective use of the services provided by thecomponent, and should provide no other information.

I The developer of a software component must beprovided with all the information necessary to carry outthe given responsibilities assigned to the component,and should be provided with no other information.

Page 29: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

COMPONENTS AND BEHAVIOR I

I A decision should be made as to the general structurethat will be used to implement each component.

I A component with only one behavior and no internalstate may be made into a function for example, acomponent that simply takes a string of text andtranslates all capital letters to lowercase.

I Components with many tasks are probably more easilyimplemented as classes.

I Names are given to each of the responsibilities identied on the CRC card for each component, and these willeventually be mapped onto method names.

I Along with the names, the types of any arguments to bepassed to the function are identi ed.

Page 30: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

COMPONENTS AND BEHAVIOR II

I Next, the information maintained within the componentitself should be described.

I All information must be accounted for.I If a component requires some data to perform a

specific task, the source of the data, either throughargument or global value, or maintained internally bythe component, must be clearly identified.

Page 31: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

COMING UP WITH NAMES I

I The following general guidelines have been suggested:I Use pronounceable names.I As a rule of thumb, if you cannot read a name out loud,

it is not a good one.I Use capitalization (or underscores) to mark the

beginning of a new word within a name, such as“CardReader” or “Card_reader”, rather than the lessreadable “cardreader”.

I Examine abbreviations carefully.I An abbreviation that is clear to one person may be

confusing to the next.I Is a “TermProcess” a terminal process, something that

terminates processes, or a process associated with aterminal?

Page 32: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

COMING UP WITH NAMES II

I Avoid names with several interpretations.I Does the empty function tell whether something is

empty, or empty the values from the object?I Avoid digits within a name.I They are easy to misread as letters (0 as O, 1 as l, 2 as

Z, 5 as S).I Name functions and variables that yield Boolean values

so they describe clearly the interpretation of a true orfalse value.

I For example, “PrinterIsReady” clearly indicates that atrue value means the printer is working, whereas“PrinterStatus” is much less precise.

I Take extra care in the selection of names for operationsthat are costly and infrequently used.

Page 33: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

COMING UP WITH NAMES III

I By doing so, errors caused by using the wrong functioncan be avoided.

I Once names have been developed for each activity, theCRC cards for each component are redrawn, with thename and formal arguments of the function used toelicit each behavior identified.

Page 34: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

DESIGNING THE REPRESENTATION I

I It is here that the classic data structures of computerscience come into play.

I The selection of data structures is an important task,central to the software design process.

I Once they have been chosen, the code used by acomponent in the fulfillment of a responsibility is oftenalmost self-evident.

I But data structures must be carefully matched to thetask at hand.

I A wrong choice can result in complex and ine cientprograms, while an intelligent choice can result in justthe opposite.

Page 35: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

IMPLEMENTING COMPONENTS I

I Implement the desired activities in a computerlanguage.

I As multiperson programming projects become thenorm, it becomes increasingly rare that any oneprogrammer will work on all aspects of a system.

I More often, the skills a programmer will need to masterare understanding how one section of code ts into alarger framework and working well with other membersof a team.

I Often, in the implementation of one component it willbecome clear that certain information or actions mightbe assigned to yet another component that will “actbehind the scene”, with little or no visibility to users ofthe software abstraction.

Page 36: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

IMPLEMENTING COMPONENTS II

I Such components are sometimes known as facilitators.I An important part of analysis and coding at this point is

characterizing and documenting the necessarypreconditions a software component requires tocomplete a task, and verifying that the softwarecomponent will perform correctly when presented withlegal input values.

Page 37: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

INTEGRATION OF COMPONENTS I

I Once software subsystems have been individuallydesigned and tested, they can be integrated into the nalproduct.

I This is often not a single step, but part of a largerprocess.

I Starting from a simple base, elements are slowly addedto the system and tested, using stubs – simple dummyroutines with no behavior or with very limited behaviorfor the as yet unimplemented parts.

I Unit testing.I Integration testing.I Regression testing.

Page 38: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

MAINTENANCE AND EVOLUTION I

I Errors, or bugs , can be discovered in the deliveredproduct.

I These must be corrected, either in updates orcorrections to existing releases or in subsequentreleases.

I Requirements may change, perhaps as a result ofgovernment regulations or standardization amongsimilar products.

I Hardware may change.I For example, the system may be moved to different

platforms, or input devices, such as a pen-basedsystem or a pressure-sensitive touch screen, maybecome available.

Page 39: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

MAINTENANCE AND EVOLUTION II

I Output technology may change for example, from atext-based system to a graphical window-basedarrangement.

I User expectations may change.I Users may expect greater functionality, lower cost, and

easier use.I This can occur as a result of competition with similar

products.I Better documentation may be requested by users.

Page 40: Object-Oriented Design

Object-OrientedDesign

MuhammadAdil Raja

Introduction

Why is OOPPolular?

Programmingin the Smalland in theLarge

Why BeginWithBehavior?

A Case Study

Components

CRC Cards

Componentsand Behavior

Preparing forChange

InteractionDiagrams

SoftwareComponents

Formalize theInterface

Designingthe Repre-sentation

ImplementingComponents

Integration ofComponents

MaintenanceandEvolution

References

REFERENCES I

I Images and content for developing these slides havebeen taken from the follwoing book.

I An Introduction to Object Oriented Programming,Timothy Budd.