Chapter 7 Object Oriented Design1
Chapter 7 Object Oriented Design1
Programming in small
Programming in the small characterizes projects with the following attributes:
• Code is developed by a single programmer, or perhaps by a very small collection of programmers.
A single individual can understand all aspects of a project, from top to bottom, beginning to end.
• The major problem in the software development process is the design and development of
algorithms for dealing with the problem at hand. Programming in large
Programming in the large characterizes software projects with features such as the following:
• The software system is developed by a large team, often consisting of people with many different
skills. No single individual can be considered responsible for the entire project, or even necessarily
understands all aspects of the project.
• With programming in the large, coding managers place emphasis on partitioning work into modules
with precisely-specified interactions. This requires careful planning and careful documentation.
• The major problem in the software development process is the management of details and the
communication of information between diverse portions of the project.
Greeter
Display informative initial message Database manager
Offer user choice of options Pass Recipe manager
control to either
• Recipe database manager
• Plan manager for processing
Card reader
Tell ATM when card is inserted ATM
Read information from card Card
Eject card
Retain card
Cash dispenser
Keep track of cash on hand, starting with Log
initial amount
Report whether enough cash is available
Dispense cash
Advantages
Sequence Diagram
Software components
• In programming and engineering disciplines, a component is an identifiable part of a larger program
or construction. Usually, a component provides a particular function or group of related functions.
In programming design, a system is divided into components that in turn are made up of modules.
Component test means testing all related modules that form a component as a group to make sure
they work together.
i) Behavior and State: One way to view a component is as a pair consisting of behaviour and state:
• The behavior of a component is the set of actions it can perform. The complete description of all
the behavior for a component is sometimes called the protocol. For the Recipe component this
includes activities such as editing the preparation instructions, displaying the recipe on a terminal
screen, or printing a copy of the recipe.
• The state of a component represents all the information held within it at a given point of time. For
our Recipe component the state includes the ingredients and preparation instructions. Notice that
the state is not static and can change over time. For example, by editing a recipe (a behavior) the
user can make changes to the preparation instructions (part of the state).
ii) Coupling and Cohesion
• Two important concepts in the design of software components are coupling and cohesion. Cohesion
is the degree to which the responsibilities of a single component form a meaningful unit. High
cohesion is achieved by associating in a single component tasks that are related in some manner.
Probably the most frequent way in which tasks are related is through the necessity to access a
common data value. This is the overriding theme that joins, for example, the various responsibilities
of the Recipe component.
• Coupling, on the other hand, describes the relationship between software components. In general,
it is desirable to reduce the amount of coupling as much as possible, since connections between
software components inhibit ease of development, modification, or reuse
iii) Interface and Implementation
It is very important to know the difference between interface and implementation. For example,
when a driver drives the car, he uses the steering to turn the car. The purpose of the steering is
known very well to the driver, but the driver need not to know the internal mechanisms of
different joints and links of various components connected to the steering.
An interface is the user’s view of what can be done with an entity. It tells the user what can be
performed. Implementation takes care of the internal operations of an interface that need not be
known to
the user. The implementation concentrates on how an entity works internally. Their comparison is
shown in Table
• The first step in this process is to formalize the patterns and channels of communication.
• A decision should be made as to the general structure that will be used to implement each
component. A component with only one behavior and no internal state may be made into a function.
Components with many tasks are probably more easily implemented as classes. Names are given to
each of the responsibilities identified on the CRC card for each component, and these will eventually
be mapped onto method names. Along with the names, the types of any arguments to be passed to
the function are identified.
• Next, the information maintained within the component itself should be described. All information
must be accounted for. If a component requires some data to perform a specific task, the source of
the data, either through argument or global value, or maintained internally by the component, must
be clearly identified.
• Names should be internally consistent, meaningful, preferably short, and evocative in the context
of the problem.
• Use pronounceable names. As a rule of thumb, if you cannot read a name out loud, it is not a good
one.
• Use capitalization (or underscores) to mark the beginning of a new word within a name, such as
“CardReader” or “Card reader”, rather than the less readable “cardreader”.
• Examine abbreviations carefully. An abbreviation that is clear to one person may be confusing to
the next. Is a “TermProcess" a terminal process, something that terminates processes, or a process
associated with a terminal?
• Avoid names with several interpretations.
• The task now is to transform the description of a component into a software system implementation
major portion of this process is designing the data structures that will be used by each subsystem to
maintain the state information required to fulfil the assigned responsibilities
• It is here that the classic data structures of computer science come into play. The selection of data
structures is an important task, central to the software design process. Once they have been chosen,
the code used by a component in the fulfilment of a responsibility is often almost selfevident. But
data structures must be carefully matched to the task at hand. A wrong choice can result in complex
and inefficient programs, while an intelligent choice can result in just the opposite.
Implementation of components
• The next step is to implement each component's desired behavior. If the previous steps were
correctly addressed, each responsibility or behavior will be characterized by a short description.
The task at this step is to implement the desired activities in a computer language.
• An important part of analysis and coding at this point is characterizing and documenting the
necessary preconditions a software component requires to complete a task, and verifying that the
software component will perform correctly when presented with legal input values. Integration of
components
• Once software subsystems have been individually designed and tested, they can be integrated into
the final product. This is often not a single step, but part of a larger process. Starting from a simple
base, elements are slowly added to the system and tested, using stubs: simple dummy routines with
no behavior or with very limited behavior: for the as yet unimplemented parts.
• Integration testing can be performed until it appears that the system is working as desired.
• Give example of car making with different components bumper, gear, engine etc.