CS6502 Notes-III Rejinpaul
CS6502 Notes-III Rejinpaul
com
www.rejinpaul.com
TEXT BOOK:
1. Craig Larman, "Applying UML and Patterns: An Introduction to Object-Oriented Analysis
and Design and Iterative Development”, Third Edition, Pearson Education, 2005.
UNIT – I
Introduction to OOAD – Unified Process - UML diagrams – Use Case – Class Diagrams–
Interaction Diagrams – State Diagrams – Activity Diagrams – Package, component and
Deployment Diagrams.
Introduction to OOAD
Object
An object is a real-world element in an object–oriented environment that may have a physical or
a conceptual existence. Each object has:
Identity that distinguishes it from other objects in the system.
State that determines the characteristic properties of an object as well as the values of the
properties that the object holds.
Behavior that represents externally visible activities performed by an object in terms of
changes in its state.
Objects can be modelled according to the needs of the application. An object may have a
physical existence, like a customer, a car, etc.; or an intangible conceptual existence, like a
project, a process, etc.
Class
A class represents a collection of objects having same characteristic properties that exhibit
common behavior. It gives the blueprint or description of the objects that can be created from it.
Creation of an object as a member of a class is called instantiation. Thus, object is an instance of
a class.
The constituents of a class are:
A set of attributes for the objects that are to be instantiated from the class. Generally,
different objects of a class have some difference in the values of the attributes.
Attributes are often referred as class data.
A set of operations that portray the behavior of the objects of the class. Operations are
also referred as functions or methods.
Example
Let us consider a simple class, Circle, that represents the geometrical figure circle in a two–
dimensional space. The attributes of this class can be identified as follows:
x–coord, to denote x–coordinate of the center
y–coord, to denote y–coordinate of the center
a, to denote the radius of the circle
Some of its operations can be defined as follows:
findArea(), method to calculate area
findCircumference(), method to calculate circumference
scale(), method to increase or decrease the radius
During instantiation, values are assigned for at least some of the attributes. If we create an object
my_circle, we can assign values like x-coord : 2, y-coord : 3, and a : 4 to depict its state. Now, if
the operation scale() is performed on my_circle with a scaling factor of 2, the value of the
variable a will become 8. This operation brings a change in the state of my_circle, i.e., the object
has exhibited certain behavior.
Encapsulation
Encapsulation is the process of binding both attributes and methods together within a class.
Through encapsulation, the internal details of a class can be hidden from outside. It permits the
elements of the class to be accessed from outside only through the interface provided by the
class.
Data Hiding
Typically, a class is designed such that its data (attributes) can be accessed only by its class
methods and insulated from direct outside access. This process of insulating an object’s data is
called data hiding or information hiding.
Example
In the class Circle, data hiding can be incorporated by making attributes invisible from outside
the class and adding two more methods to the class for accessing class data, namely:
setValues(), method to assign values to x-coord, y-coord, and a
Message Passing
Any application requires a number of objects interacting in a harmonious manner. Objects in a
system may communicate with each other using message passing. Suppose a system has two
objects: obj1 and obj2. The object obj1 sends a message to object obj2, if obj1 wants obj2 to
execute one of its methods.
The features of message passing are:
Message passing between two objects is generally unidirectional.
Message passing enables all interactions between objects.
Message passing essentially involves invoking class methods.
Objects in different processes can be involved in message passing.
Inheritance
Inheritance is the mechanism that permits new classes to be created out of existing classes by
extending and refining its capabilities. The existing classes are called the base classes/parent
classes/super-classes, and the new classes are called the derived classes/child classes/subclasses.
The subclass can inherit or derive the attributes and methods of the super-class(es) provided that
the super-class allows so. Besides, the subclass may add its own attributes and methods and
may modify any of the super-class methods. Inheritance defines an “is – a” relationship.
Example
From a class Mammal, a number of classes can be derived such as Human, Cat, Dog, Cow, etc.
Humans, cats, dogs, and cows all have the distinct characteristics of mammals. In addition, each
has its own particular characteristics. It can be said that a cow “is – a” mammal.
Types of Inheritance:
Single Inheritance : A subclass derives from a single super-class.
Multiple Inheritance : A subclass derives from more than one super-classes.
Polymorphism
Polymorphism is originally a Greek word that means the ability to take multiple forms. In
object-oriented paradigm, polymorphism implies using operations in different ways, depending
upon the instance they are operating upon. Polymorphism allows objects with different internal
Generalization
In the generalization process, the common characteristics of classes are combined to form a class
in a higher level of hierarchy, i.e., subclasses are combined to form a generalized super-class. It
represents an “is – a – kind – of” relationship. For example, “car is a kind of land vehicle”, or
“ship is a kind of water vehicle”.
Specialization
Specialization is the reverse process of generalization. Here, the distinguishing features of
groups of objects are used to form specialized classes from existing classes. It can be said that
the subclasses are the specialized versions of the super-class.
The following figure shows an example of generalization and specialization.
Link
A link represents a connection through which an object collaborates with other objects.
Rumbaugh has defined it as “a physical or conceptual connection between objects”. Through a
link, one object may invoke the methods or navigate through another object. A link depicts the
relationship between two or more objects.
Association
Association is a group of links having common structure and common behavior. Association
depicts the relationship between objects of one or more classes. A link can be defined as an
instance of an association.
Degree of an Association
Degree of an association denotes the number of classes involved in a connection. Degree may be
unary, binary, or ternary.
A unary relationship connects objects of the same class.
A binary relationship connects objects of two classes.
A ternary relationship connects objects of three or more classes.
Aggregation or Composition
Aggregation or composition is a relationship among classes by which a class can be made up of
any combination of objects of other classes. It allows objects to be placed directly within the
body of other classes. Aggregation is referred as a “part–of” or “has–a” relationship, with the
ability to navigate from the whole to its parts. An aggregate object is an object that is composed
of one or more other objects.
Example
In the relationship, “a car has–a motor”, car is the whole object or the aggregate, and the motor
is a “part–of” the car. Aggregation may denote:
Physical containment : Example, a computer is composed of monitor, CPU, mouse,
keyboard, and so on.
Conceptual containment : Example, shareholder has–a share.
Software Quality
There are two basic approaches to systems testing.
We can test a system according to how it has been built.
Alternatively, we can test the system with respect to what it should do.
Quality Measures
o Correctness measures the consistency of the product requirements with respect to the design
specification.
Object–Oriented Analysis
In this stage, the problem is formulated, user requirements are identified, and then a model is
built based upon real–world objects. The analysis produces models on how the desired system
should function and how it must be developed. The models do not include any implementation
details so that it can be understood and examined by any non–technical application expert.
Object–Oriented Design
Object-oriented design includes two main stages, namely, system design and object design.
SYSTEM DESIGN
In this stage, the complete architecture of the desired system is designed. The system is
conceived as a set of interacting subsystems that in turn is composed of a hierarchy of
interacting objects, grouped into classes. System design is done according to both the
system analysis model and the proposed system architecture. Here, the emphasis is on
the objects comprising the system rather than the processes in the system.
OBJECT DESIGN
In this phase, a design model is developed based on both the models developed in the
system analysis phase and the architecture designed in the system design phase. All the
classes required are identified. The designer decides whether:
Prototyping
A Prototype enables you to fully understand how easy or difficult it will be to implement
some of the features of the system.
It can also give users a chance to comment on the usability and usefulness of the design.
Types of Prototypes
A horizontal prototype is a simulation of the interface.
A domain prototype is an aid for the incremental development of the ultimate software
solution.
• RAD does not replace SDLC but complements it, since it focuses more on process description
and can be combined perfectly with the object-oriented approach.
Incremental Testing
• Software development and all of its activities including testing are an iterative process.
• If you wait until after development to test an application for bugs and performance, you could
be wasting thousands of dollars and hours of time.
Reusability A major benefit of object-oriented systems development is reusability, and this is the
most difficult promise to deliver on.
Reuse strategy
o Information hiding (encapsulation).
The essence of the software process is the transformation of users‘ needs into a software
solution. The O-O SDLC is an iterative process and is divided into analysis, design, prototyping/
implementation, and testing.
Here, we look at the methodologies developed by Rumbaugh et al., Booch, and Jacobson
which are the origins of the Unified Modeling Language (UML) and the bases of the UA
Rumbaugh Methodologies OMT (Object Modeling Technique) describes a method for the
analysis, design, and implementation of a system using an object-oriented technique. Class
attributes, method, inheritance, and association also can be expressed easily Phases of OMT
Analysis
System Design
Object Design
Implementation
Object design. This phase produces a design document, consisting of detailed objects and
dynamic and functional models.
Implementation. This activity produces reusable, extendible, and robust code.
Object Modelling
Object modelling develops the static structure of the software system in terms of objects. It
identifies the objects, the classes into which the objects can be grouped into and the relationships
between the objects. It also identifies the main attributes and operations that characterize each
class.
The process of object modelling can be visualized in the following steps:
Dynamic Modelling
After the static behavior of the system is analyzed, its behavior with respect to time and external
changes needs to be examined. This is the purpose of dynamic modelling.
Dynamic Modelling can be defined as “a way of describing how an individual object responds
to events, either internal events triggered by other objects, or external events triggered by the
outside world”.
The process of dynamic modelling can be visualized in the following steps:
Functional Modelling
Functional Modelling is the final component of object-oriented analysis. The functional model
shows the processes that are performed within an object and how the data changes as it moves
between methods. It specifies the meaning of the operations of object modelling and the actions
of dynamic modelling. The functional model corresponds to the data flow diagram of traditional
structured analysis.
The process of functional modelling can be visualized in the following steps:
Booch Methodology
The Booch methodology covers the analysis and design phases of systems development.
Booch sometimes is criticized for his large set of symbols.
The Booch method consists of the following diagrams:
Class diagrams o Object diagrams
State transition diagrams
Module diagrams
Process diagrams
Interaction diagrams
The Macro Development Process It serves as a controlling framework for the micro process.
The primary concern is Technical Management of the System. The macro development process
consists of the following steps:
1. Conceptualization
2. Analysis and development of the model.
3. Design or create the system architecture.
4. Evolution or implementation.
5. Maintenance.
Conceptualization:
• Establish the core requirements of the system
• Establish a set of goals and develop prototype to prove the concept
Evolution or implementation
o Successively refine the system through many iterations
o Produce a stream of software implementations, each of which is refinement of the prior one
Maintenance
o Make localized changes to the system to add new requirements and eliminate bugs
Jacobson Methodologies The Jacobson et al. methodologies (e.g., OOBE, OOSE, and
Objectory) cover the entire life cycle and stress traceability between the different phases.
o Use cases again are the central vehicle for modeling, providing traceability throughout the
software engineering processes.
• OOBE consists of :
– Analysis phase
– Design
– Implementation phases and
– Testing phase.
Feasibility Study
Requirement Analysis and Specification
System Design
Implementation
Post-implementation Review
Advantages Disadvantages
Agile Methodology
Agile SDLC model is a combination of iterative and incremental process models with focus on
process adaptability and customer satisfaction by rapid delivery of working software product.
Agile Methods break the product into small incremental builds. These builds are provided in
iterations. Each iteration typically lasts from about one to three weeks. Every iteration involves
cross functional teams working simultaneously on various areas like planning, requirements
analysis, design, coding, unit testing, and acceptance testing.
Following table lists out the pros and cons of Agile Model:
Pros Cons
Is a very realistic approach to software Not suitable for handling complex
development dependencies.
Promotes teamwork and cross training. More risk of sustainability,
Functionality can be developed rapidly maintainability and extensibility.
and demonstrated. An overall plan, an agile leader and
Resource requirements are minimum. agile PM practice is a must without
Suitable for fixed or changing which it will not work.
requirements Strict delivery management dictates the
Delivers early partial working solutions. scope, functionality to be delivered, and
Good model for environments that adjustments to meet the deadlines.
change steadily. Depends heavily on customer
Minimal rules, documentation easily interaction, so if customer is not clear,
employed. team can be driven in the wrong
Enables concurrent development and direction.
Agile is based on the adaptive software development methods where as the traditional
SDLC models like waterfall model is based on predictive approach. Customer interaction is the
backbone of Agile methodology, and open communication with minimum documentation are the
typical features of Agile development environment. The agile teams work in close collaboration
with each other and are most often located in the same geographical location.
Unified Process
Unified Process is a popular iterative process for projects using object oriented analysis and
design. UP make use of best practices such as iterative life cycle and risk-driver development to
provide a well documents process description.
The Unified Process supports the following
1. Evolution of project plans, requirements and software architecture with well-
defined synchronization points
2. Risk management
3. Evolution of system capabilities through demonstrations of increasing
functionality
It emphasizes the difference between engineering and production.
• Engineering Stage
• Driven by less predictable but smaller teams, focusing on design and synthesis
activities
• Production Stage
• Driven by more predictable but larger teams, focusing on construction, test and
deployment activities
What is a workflow?
A set of activities that is performed by the various roles in a project
Describes a meaningful sequence of activities that produce a useful result (an artifact)
Shows interaction between roles
Three key elements of each workflows:
o Artifacts
o Roles
o Activities
Artifact: A work product in a uniform representation format (natural language, UML, Java,
binary code,…)
Activities
Tasks performed by people representing particular roles in order to produce artifacts
Architecture-centric
The Unified Process insists that architecture sit at the heart of the project team's efforts to
shape the system. Since no single model is sufficient to cover all aspects of a system, the Unified
Process supports multiple architectural models and views. One of the most important
deliverables of the process is the executable architecture baseline which is created during the
Elaboration phase. This partial implementation of the system serves to validate the architecture
and act as a foundation for remaining development.
Risk-focused
The Unified Process requires the project team to focus on addressing the most critical risks early
in the project life cycle. The deliverables of each iteration, especially in the Elaboration phase,
must be selected in order to ensure that the greatest risks are addressed first.
The two stages of the Unified Process are decomposed into four distinct phases
• Engineering stage
• Production phase
Inception Phase
• Capture requirements
► Vision: The project's core requirements, key features, and main constraints are
documented. Stakeholders …
► Software Development Plan: all information required to manage the project. (Risk, time
and durations, needed tools, changes, documentations)
► Use-case model: a model of the system's intended functions and its environment, and
serves as a contract between the customer and the developers.
• Do all stakeholders concur on the scope definition and cost and schedule estimates?
• Are the requirements understood, are the critical use cases adequately modeled?
• Are cost, schedule estimates, priorities, risks and development processes credible?
Elaboration Phase
• Establish a configuration management plan in which all changes are tracked and
maintained
• Base line the software project management plan for the construction phase
Question: Why does the Unified process not recommend the establishment of a configuration
management plan during the inception phase?
• Elaborate the problem statement (“vision”) by working out the critical use cases that
drive technical and managerial decisions.
• Tailor the software process for the construction stage, identify tools.
• Identify lessons learned from the inception phase to redesign the software architecture if
necessary (“always necessary”:-)
► Design model: an object model describing the realization of use cases, and serves as an
abstraction of the implementation model and its source code.
► Data model: a subset of the implementation model which describes the logical and
physical representation of persistent data in the system.
• Does the executable demonstration show that the major risk elements have been
addressed and credibly resolved?
• Do all stakeholders (project participants) agree that the vision expressed in the
problem can be met if the current plan is executed?
Construction Phase
• Achieve useful version (alpha, beta, and other test releases) as soon as possible
► The System: The executable system itself, ready to begin "beta" testing.
► Training materials: the material that is used in training programs or courses to assist the
end-users with product use, operation and/or maintenance.
• Are the stakeholders ready for the transition of the software system to the user
community?
Transition Phase
• A usable subset of the system has been built with acceptable quality levels and
user documents
• For some projects the transition phase means the starting point for another version of the
software system
• For other projects the transition phase means the complete delivery of the software
system to a third party responsible for operation, maintenance and enhancement.
• Deployment baseline is complete and consistent with the criteria in the project agreement
► Product.
► Release Notes: identify changes and known bugs in a version of a build or deployment
unit that has been made available for use.
► End-User Support Material: Materials that assist the end-user in learning, using,
operating and maintaining the product.
• Each of the four phases introduced so far (inception, elaboration, construction, transition)
consists of one or more iterations
• The scope and results of the iteration are captured via work products (called
artifacts in the UP).
• Artifact set:
• Management set
• Requirements set
• Design set
• Implementation set
• Deployment set
• The main motivation here is to combine the best practices, processes, methodologies, and
guidelines along with UML notations and diagrams.
Object-oriented analysis.
Object-oriented design.
Continuous testing.
The interaction between objects provide a map for the design phase to model the
relationships and designing classes.
UA Object-Oriented Design
Booch provides the most comprehensive object-oriented design method.
However, Booch methods can be somewhat imposing to learn and especially tricky to
figure out where to start.
UA realizes this by combining Jacobson et al.'s analysis with Booch's design concept to
create a comprehensive design process.
The Layered Approach to Software Development Most systems developed with today's CASE
tools or client-server application development environments tend to lean toward what is known
as two-layered architecture: interface and data.
Two-Layer Architecture
In a two-layer system, user interface screens are tied directly to the data through routines that sit
directly behind the screens
Problem with the Two-Layer Architecture This approach results in objects that are very
specialized and cannot be reused easily in other projects.
Three-Layer Architecture Your objects are completely independent of how:
.
User Interface layer This layer is typically responsible for two major aspects of the applications:
Data Workstation Owner Name Title Address
• Responding to user interaction
Business Layer
The responsibilities of the business layer are very straight- forward:
model the objects of the business and how they interact to accomplish the business
processes.
Introduction to Modelling
Describing a system at a high level of abstraction
o A model of the system
o Used for requirements and specifications
o Is it necessary to model software systems?
History of UML
- Structure diagrams emphasize on the things that must be present in the system being modeled.
- Since structure diagrams represent the structure, they are used extensively in documenting the
software architecture of software systems.
Behavioural Diagrams
- Behavior diagrams emphasize on what must happen in the system being modeled.
- Since behavior diagrams illustrate the behavior of a system, they are used extensively to
describe the functionality of software systems.
Purpose:
o The main purpose of the use case diagram is to capture the dynamic aspect of a system.
o Use case diagram shows, what software is suppose to do from user point of view.
o It describes the behavior of system from user’s point.
o It provides functional description of system and its major processes.
o Use case diagram defines the scope of the system you are building.
CLASS DIAGRAM
Introduction
o The class diagram is a static diagram.
o A class model captures the static structure of a system by characterizing the objects in the
system, the relationship between the objects, and the attributes and operations for each class
of objects.
o The class diagram can be mapped directly with object oriented languages.
o The class model is the most important among the three models.
o Class diagram provide a graphical notation for modeling classes and their relationship.
Purpose
o Analysis and design of the static view of an application.
o Describe responsibilities of a system.
o Base for component and deployment diagrams.
Purpose
o The state model describes those aspects of objects concerned with time and the sequencing
of operations events that mark changes, states that define the context for events, and the
organization of events and states.
o They are used to give an abstract description of the behavior of a system.
o It provides direction and guidance to the individual counties within the states.
o It specifies the possible states, what transitions are allowed between states.
o It describes the common behavior for the objects in a class and each object changes its
behavior from one state to another.
INTERACTION DIAGRAM
This interactive behaviour is represented in UML by two diagrams known as
Sequence Diagram
Collaboration Diagram
Purpose
o The main purpose of this diagram is to represent how different business objects interact.
o A sequence diagram shows object interactions arranged in time sequence.
o It depicts the objects and classes involved in the scenario and the sequence of messages
exchanged between the objects needed to carry out the functionality of the scenario.
ACTIVITY DIAGRAM
Introduction
o An activity diagram is a type of flow chart with additional support for parallel behavior.
o This diagram explains overall flow of control.
o Activity diagram is another important diagram in UML to describe dynamic aspects of the
system.
o Activity diagram is basically a flow chart to represent the flow from one activity to another
activity
Purpose
o Contrary to use case diagrams, in activity diagrams it is obvious whether actors can perform
business use cases together or independently from one another.
o Activity diagrams allow you to think functionally.
o Because it is possible to explicitly describe parallel events, the activity diagram is well suited
for the illustration of business processes, since business processes rarely occur in a linear
manner and often exhibit parallelisms.
o This diagram is useful to investigate business requirements at a later stage.
DEPLOYMENT DIAGRAM
Deployment diagrams are used to visualize the topology of the physical components of a system
where the software components are deployed. So deployment diagrams are used to describe the
static deployment view of a system. Deployment diagrams consist of nodes and their
relationships.
Purpose:
The purpose of deployment diagrams can be described as:
Deployment diagrams are useful for system engineers. An efficient deployment diagram is very
important because it controls the following parameters
Performance
Scalability
Maintainability
Portability
Nodes
The following deployment diagram is a sample to give an idea of the deployment view of order
management system. Here we have shown nodes as:
Monitor
Modem
Caching server
Server
So the following deployment diagram has been drawn considering all the points mentioned
above:
COMPONENT DIAGRAM
Component diagrams are different in terms of nature and behaviour. Component diagrams are
used to model physical aspects of a system.
Purpose:
Component diagram is a special kind of diagram in UML. The purpose is also different from all
other diagrams discussed so far. It does not describe the functionality of the system but it
describes the components used to make those functionalities.
So from that point component diagrams are used to visualize the physical components in a
system. These components are libraries, packages, files etc. Component diagrams can also be
described as a static implementation view of a system. Static implementation represents the
organization of the components at a particular moment.
A single component diagram cannot represent the entire system but a collection of diagrams are
used to represent the whole.
Component diagrams are used to describe the physical artifacts of a system. This artifact
includes files, executables, libraries etc. So the purpose of this diagram is different, Component
diagrams are used during the implementation phase of an application.
So the following component diagram has been drawn considering all the points mentioned
above:
OBJECT DIAGRAM
Object diagrams are derived from class diagrams so object diagrams are dependent upon class
diagrams. Object diagrams represent an instance of a class diagram. The basic concepts are
similar for class diagrams and object diagrams. Object diagrams also represent the static view of
a system but this static view is a snapshot of the system at a particular moment. Object diagrams
are used to render a set of objects and their relationships as an instance.
Purpose:
Second, consider only those instances which will cover the functionality.
Customer
Order
SpecialOrder
NormalOrder
Now the customer object (C) is associated with three order objects (O1, O2 and O3). These
order objects are associated with special order and normal order objects (S1, S2 and N1). The
customer is having the following three orders with different numbers (12, 32 and 40) for the
particular time considered. Now the customer can increase number of orders in future and in
that scenario the object diagram will reflect that. If order, special order and normal order objects
are observed then you will find that they are having some values. For orders the values are 12,
32, and 40 which implies that the objects are having these values for the particular moment
(here the particular time when the purchase is made is considered as the moment) when the
instance is captured. The same is for special order and normal order objects which are having
number of orders as 20, 30 and 60. If a different time of purchase is considered then these
values will change accordingly. So the following object diagram has been drawn considering all
the points mentioned above:
Reverse engineering.
PACKAGE DIAGRAM
• A package is used to group elements, and provides a namespace for the grouped
elements. A package is a namespace for its members, and may contain other packages.
• Package can also be merge with other package, thus provide the hierarchical organization
of the package.
• The elements that can be referred to within a package using non-qualified names are:
Owned Element, Imported Element, and elements enclosing namespaces.
• Owned and imported elements may have a visibility that determines whether they are
available outside the package.
• Package org.hibernate
• Members of the package may be shown outside of the package by branching lines.
• Nested packages.
• All elements of Library Domain package are public except for Account.
• If a package is removed from the model, so are all the elements owned by the package.
Package by itself is packageable element, so any package could be also a member of the
other packages.
• Dependency
• Generalization
• Refinement
Dependency
Generalization
Refinement
• One Package refines another package, if it contains same elements but offers more
details about those elements.
Package Import
Package Merge
• It indicates that content of one package is extended by the contents of another package.
• Package merge used when elements defined in different packages have the same name
and are intended to represent the same concept.
• Package merge is shown using a dashed line with an open arrowhead pointing from the
receiving package to the merged package.
Model
• Model is notated using the ordinary package symbol (a folder icon) with a small triangle
in the upper right corner of the large rectangle.
• If contents of the model are shown within the large rectangle, the triangle may be drawn
to the right of the model name in the tab.
Package Relationship
• Ex. If changing the contents of a package, P2, affects the contents of another package,
P1, we can say that P1 has a Package Dependency on P2.
• A large complex project can hundred of classes. Without some way to organization
those classes. It becomes impossible to make sense of tem all.
• Packages create a structure for you classes or other Uml element by grouping related
elements.
• With the large system to show its major element and how they relate to one another.
• Package diagrams can use packages that represent the different layers of a software
system to illustrate the layered architecture of a software system.
Unit – 2
GRASP INTRODUCTION
What is Pattern?
It is common that when experts works on particular problems, they need not reinvent the wheel
i.e. they need not find a complete new solution that is completely different from existing
solutions. Rather they remember the similar problem and it solution and reuse the core of it for
solving new problem. They think in terms of “Problem Solution” pairs. Abstracting from such
pairs and churning out the commonalities leads to patterns.
Each pattern is three-part rule which expresses a relation between a certain context, a problem
and a solution.
Patterns have names and they facilitate communication- common vocabulary and understanding-
easy to remember whole concept in a nutshell.
GRASP:
Craig Larman coined these terms for the first time.
stands for General Responsibility Assignment Software Patterns.
The mnemonic meaning could be “successful OOAD (Object Oriented Analysis & Design)
requires grasping (understanding)”.
General: = Abstract i.e. widely applicable for variety of situations
Responsibility: = Obligations, duties –information object performing duty of holding
information, computational object performing duty of computation
Assignment: = Giving a responsibility to a module- capability to carry out responsibility
structure and methods
Software: = Computer code
Patterns: = Regularities, templates, abstraction
Assigning responsibilities to objects is always is major task in designing the software’s.
Specifically it’s always a challenge to decide which object carry out what job (responsibilities)
and quality of software design largely depended upon such responsibilities assignment.
Poor choices about such responsibities leads to fragile systems and components which are hard
to maintain, understand, reuse or extend.
Information Expert
Creator
Controller
Low Coupling
High Cohesion
Polymorphism
Pure Fabrication
Indirection
Protected Variations.
Information Expert
Objective
To understand about the GRASP pattern “Information Expert’.
Problem: Any real world application has hundreds of classes and thousand of actions. How do I
start assigning the responsibility?
Solution: Assign a responsibility to Information Expert, the class that has information necessary
to fulfil the responsibility.”
Generally, if domain model is ready then it is pretty straight forward to assign the responsibilities
and arrive at design model.
Approach
Step I: State the responsibility clearly.
Step II: Search for the classes who have the information needed to fulfil the responsibility.
Step III: Assign the responsibility
Description
Let’s take an example of POS (Point Of Sale) systems. This is what we come across malls where
there are many POS counters. In the domain model, following classes are identified. These
classes are shown in the left part of diagram (Fig. No.1). Let’s think about some responsibility.
In the above scenario, the classes Sale, “SaleLineItem” and “ProductSpecification” has the
information such as unit price for item/ product (“ProductSpecification”), sales quantity
(“SaleLineItem”) and no. of saleLineItems (“Sale”). So the responsibility of arriving at Sales
Total needs to be assigned to all these classes. Now in this case, If the class is encapsulating data
members then maintaining these data values is the responsibility of the class and it should
provide the get and set methods for accessing such data.
Class Data Values Encapsulated Responsibility and
method
ProductDescription UnitPrice Getting the unit price
getPrice()
SaleLineItem Quantity of items and hence the Getting the Subtotal
subtotal for particular item getSubTotal()
Quantity X Unit Price
Sale No. of Saleline Items, data and Get the Total of Sales
time getTotal()
Sum of (getSubTotal() x
SaleLine item )
Benefits:
Encapsulation is maintained as objects use their own data to fulfil the task.
Support low coupling
Behaviour (responsibility) is distributed across the classes that have the required
information thus encouraging the highly cohesive lightweight classes
Liabilities /Contradictions:
Sometimes while assigning responsibilities, lower level responsibilities are uncovered e.g
what the profit or loss for a particular sale?
Not all the times the application of this pattern is desirable. Consider the responsibility of
saving such Sale to database. By the principle for this pattern, it should be the class
“Sale” to carry out this responsibility but as experienced programmer we know it is
hardly the case. The DAL (Data Access Layer) carries out this responsibilities may be by
providing methods such as SaveSale() into some controller class.
Creator
Objective
To understand the GRASP pattern “Creator”.
Solution:
Assign class A the responsibility to create an instance of class B if….
· A aggregates (whole-part relationship) B objects
· A contains B objects
· A records instances of B objects
· A closely uses B objects
· A has initializing data that is needed while creating B objects (thus A is an expert
with respect to creating B)
Approach:
Step I: Closely look at domain/ design model and ask: who should be creating these
classes?
Step II: Search for the classes who create, aggregate etc.
Step III: Assign the responsibility of creation
Description
Let’s extend an example of POS (Point Of Sale) systems explained in previous part. This is what
we come across malls where there are many POS counters. In the domain model, following
classes are identified. These classes are shown in the left part of diagram (Fig. No.1). A class
“Register” represents the sales register. This would have details of all sales done. As the
“Register” aggregates the “Sale”, it fulfils the first criteria of the solution. Similarly the “Sale”
contains the “SaleLineItem”. Hence “Register” should create the instance of “Sale” and “Sale”
should create instance of “SaleLineItem”.
Fig. No. 1
Table No. 1
Class Relationship with other Responsibility and
classes method
Register Contains Class “Sale” Creating an instance
createSale()
Sale Composite aggregation with Creating an instance
SaleLineItem makeSaleLineItem()
Benefits:
· Support low coupling
· The responsibility is assigned to a class which fulfils the criteria thus separating the
logic for creation and actual execution.
Liabilities /Contradictions:
· Sometimes creation may require significant complexity. Many a times there would be
tight coupling among the creator and create class. Also the task of destroying the
objects is to be thought of. Recycling of such instances (pooling) becomes important for
the performance reasons.
· In many scenarios the creations is conditional and it may be from family of classes
making it very complex.
· For creation of family of classes or to tackle the creation and recycling, other patterns
are available which are factory, abstract factory etc.
Controller
Objective
To understand the GRASP pattern “Controller”
Problem: Who should be responsible for handling a system event?
Solution: Assign the responsibility for handling a system event message to a class representing
one of the following
A class that represents the overall system, device, or sub-system(facade controller) e.g.
Jukebox.
A class that represents a use case within which the system event occurs
(a session controller
or use case controller)Example: makeSaleHandler, makeSaleCoordinator, etc.
Represents the overall business (facade controller)
Represents something in real world that is active (role controller)
These classes often don’t do the work themselves, but delegate it to others and in other terms it
coordinates or controls the activity. The decision to create the specific controller i.e. system
controllers vs. use case controllers are often driven and influenced by the dynamics of high
cohesion vs. low coupling scenario.
Approach:
Step I: Closely look at domain/ design model and when you have family of classes doing
work/job pertaining to some specific function and would need some facilitator
e.g. if one has requirement to connect to multiple databases and has the DAL, a
CommunicationManager class can be introduced to control and manage DAL and connection to
different database
Step II: Add a new class to take the responsibility of controller or manager and all client code
would access the functionality through this class
Description
Let’s extend an example of POS (Point Of Sale) systems explained in previous part. In the
domain model, following classes are identified. These classes are shown in the left part of
diagram (Fig. No.1). There are many system operations such as closing a sale, make payment etc
which are related to business function “Sales”.
Controller pattern gives following choices
Following diagram depicts the Controller pattern. Compared to Creator pattern, it has additional
class called makeSaleHandler (in fact the “Register” class shown in the article for Creator pattern
can be called as controller) which controls and coordinates the sale.
Cashier - represents some role in real-world that is active in the task
UI Form- shows the UI layer for POS software system
This is an example of a use case handler which would be used to deal with all system events of a
use case, and may be used for more than one use case (e.g. for use cases “Create User” and
“Delete User”, one can have one UserController, instead of two separate controllers). In this case
the use case is “Create SaleLineItem”
If you choose use case controller,, you might want to use the some controller class for all system
in a particular use case scenario. E.g. for POS system one can have POSController through
which all system events would be routed to domain (as well as business logic) layer. In some
scenarios, the only reason for not doing so is that the class can become too complex and it
becomes better to delegate the work.
Controller is defined as the first object beyond the UI layer that receives and coordinates
("controls") a system operation (triggered by user of the system). The controller should delegate
to other objects the work that needs to be done; it should not do much work itself. The GRASP
Controller can be thought of as being a part of the Application/Service layer (assuming that the
application has made an explicit distinction between the Application/Service layer and the
Domain layer) in object-oriented systems with layered pattern implemented.
What such controller does?
o It sees to it that the messages are sent to the correct expert in the model. (e.g.
“Sale” class)
o The reason to have a controller is to separate the business model called
domain objects from the visual logic called view objects
Once the decision to have a controller is decided, the real question is choosing which concept is
to be the controller class
o This is relatively easy as the concept that processes the system events is the
logical choice
o In the above case, cashier is really an actor the runs the posting of sale. Hence
it can’t be a controller.
The classes which represent the overall system, sub-system or devices are called as Facade
controllers and it is suitable when there are few events.
When Use-case controllers are used, there will be one controller for each use-case.
Bloated Controller: There are the controllers which handle too many system events leading to
low cohesion. This would happen when only one class is receiving all system events. These
perform many of the tasks for handling events without delegating the work and also has
significant amount of information which should have distributed to other project. Sometimes it
duplicates information found somewhere else. Such controller better be avoided and they can be
avoided by addition of few more controllers.
Design the controller in such a way that it primarily delegates the fulfillment of each system
operation to other objects.
Related Patterns: This patterns needs to be studied from the angle of understanding and
applying principle. The patterns related to this are “Low Coupling” and “High Cohesion”.
Benefits:
· Supports Low Coupling
· Promotes Understandability, maintainability
Liabilities /Contradictions:
· Sometimes grouping of responsibilities or code into one class or component to
simplify maintenance occurs when controllers are designed. This should be avoided as it
would become bloated controllers as discussed above.
Low Coupling
Objective
To understand the GRASP pattern “Low Coupling”
The principle behind this pattern is “How to support low dependency and increased
reuse?” and “How to assign the responsibilities so that the coupling is low?”
Coupling refers to connectedness or linking. It is a measure of how strongly one class is
connected to or has knowledge (information or knowhow) of or relies/depends upon the other
classes. With experience, programmers would agree on something i.e. making changes is always
been the hardest task and given a chance all would like to work upon systems from ground up.
With increased complexity in the programming world and programming languages, designing is
becoming driver for system’s overall quality and usability. Designing for low connectedness is
an important activity which can help to have a system in such a way that the changes in one
element (sub-system, system, class, etc) will limit changes to other elements. Being at extreme,
is it possible to have no coupling at all? The answer to this question is “No” as without having
any connection; a system can’t be called a system.
High coupling (high dependency, linking and connectedness) leads to
Approach:
Step I: Closely look for classes with many associations to other classes.
Step II: Look for the methods that rely on a lot of other methods (or methods in other
classes i.e. dependencies
Step III: Rework the design so as assign responsibilities to different classes in such a
way that they have lesser association and dependency.
Description
Let’s extend an example of POS (Point Of Sale) systems carried in series of articles. In the
domain model, following classes like Register, Payment and Sale are identified. These classes
are shown in the left part of diagram (Fig. No.1). There are many system operations such as
closing a sale, make payment etc which are related to business function “Sales”.
Fig No. 1
Table No. 1
Class Relationship with other Responsibility and method Remarks
classes
“Register” Creator of the “Payment” Controls and coordinates the So if Sale or payment
of Design Controls the “Sale” sale through makePayment() changes its going to
I affect the Register.
This results in tight
coupling
“Register” Controller of “Sale” and Creating an instance This results in
and “Sale” being the creator “create” division of
“Sale” of of “Payment” Controlling the Sale through responsibilities and
Design II makePayment() hence low coupling
as “Register” need
not know about the
payment.
Liabilities / Contradictions:
· Coupling to stable elements (classes in library or well tested classes) doesn’t account
to be a problem.
High Cohesion
Objective
To understand the GRASP pattern “High Cohesion”
The dictionary meaning of the word “cohesion” is “the state of cohering or sticking
together”. In botany world “the process of some parts (which are generally separate) of plant
growing together” and in physics world “it’s the intermolecular force that holds together the
molecules in solid or liquid”. So this meaning would give us good forethought as what would
“High Cohesion” would mean in the context of responsibilities? As we have proceeded through
this series, we have seen principles behind assigning the responsibilities. Once they are assigned
or being assigned, an important aspect is how they are related or focused? If they are related,
sticking together or focussed, the element carrying to those responsibilities would become
bloated and result into system quite complex and harder to maintain and reuse. The principle
behind this pattern is “How to keep complexity manageable?
Cohesion can be said to a measure of “relatedness” or “how related all the attributes
and behaviour in a class are”. High cohesion refers to how strongly related the responsibilities
are.
A class with low cohesion i.e. carrying out the unrelated responsibilities in turn does so
many unrelated things or end up doing too much of a work. Such classes culminates into
Approach:
Step I: Closely look for classes with probability of many responsibilities i.e. classes with
too-few or disconnected methods.
Step II: Look for the methods which do a lot (look for method names having words like
“AND”, “OR”)
Step III: Assign a responsibility in such a way that all the responsibilities in a class are
related
Description
Let’s extend an example of POS (Point Of Sale) systems carried in series of articles. In the
domain model, following classes like Register, Payment and Sale are identified. In the upper part
of diagram (Fig. No.1) a class “Register” is displayed carrying out many unrelated
responsibilities. There are many system operations such as closing a sale, make payment etc
which are related to business function “Sales”.
Fig No. 1
System level: ATM having functionality for getting “Teller Reports” i.e. for user this
is not required and related
Class level: An “Employee” class with a method called “getDrivingRecords()”
Method level: The methods with having “AND”,”OR” in their names which implies
that the method is going to execute multiple functions making it difficult to reuse.
This also applies to subsystem (package), component level. E.g. a component for
exception handling also doing job of caching.
One of the fundamental goals of an effective design is to achieve high cohesion with low
coupling.
Related Patterns: This pattern is related rather complementary to “Low Coupling” and little
contradictory to information expert.
Benefits
Liabilities / Contradictions:
· In scenarios of server objects, it would be desirable to have less cohesive server
objects due t o performance needs. Remote objects and remote communication are the
examples where performance matters than anything else. In this case, an interface
provided for many operations would be recommended than having highly cohesive but
different interfaces/ components.
· While grouping the responsibilities or code into one class or component motivated by
maintainability from view of one person is not desirable as it would end up in
maintainability for one person but not for all. This happens when the responsibilities
could be related to class but not to each other. This is a good trap for any developer who
can never imagine there would be somebody else working on it and he/she has preferred
to keep things at one place for better traceability.
A design patterns are well-proved solution for solving the specific problem/task.
Now, a question will be arising in your mind what kind of specific problem? Let me explain by
taking an example.
Problem Given:
Suppose you want to create a class for which only a single instance (or object) should be created
and that single object can be used by all other classes.
Solution:
Singleton design pattern is the best solution of above specific problem. So, every design pattern
has some specification or set of rules for solving the problems. What are those specifications,
you will see later in the types of design patterns.
We must use the design patterns during the analysis and requirement phase of
SDLC(Software Development Life Cycle).
Design patterns ease the analysis and requirement phase of SDLC by providing information
based on prior hands-on experiences.
1. Factory Pattern
2. Factory Method Pattern
3. Abstract Factory Pattern
4. Singleton Pattern
5. Prototype Pattern
6. Builder Pattern.
1. Adapter Pattern
2. Bridge Pattern
3. Composite Pattern
4. Decorator Pattern
5. Facade Pattern
6. Flyweight Pattern
7. Proxy Pattern
5. Mediator Pattern
6. Memento Pattern
7. Observer Pattern
8. State Pattern
9. Strategy Pattern
10. Template Pattern
11. Visitor Pattern
Creational Pattern
Factory Method
Factory Method
Intent
Define an interface for creating an object, but let subclasses decide which class to
instantiate. Factory Method lets a class defer instantiation to subclasses.
Problem
A framework needs to standardize the architectural model for a range of applications, but allow
for individual applications to define their own domain objects and provide for their instantiation.
Discussion
Factory Method is to creating objects as Template Method is to implementing an algorithm. A
superclass specifies all standard and generic behavior (using pure virtual "placeholders" for
creation steps), and then delegates the creation details to subclasses that are supplied by the
client.
Factory Method makes a design more customizable and only a little more complicated. Other
design patterns require new classes, whereas Factory Method only requires a new operation.
People often use Factory Method as the standard way to create objects; but it isn't necessary if:
the class that's instantiated never changes, or instantiation takes place in an operation that
subclasses can easily override (such as an initialization operation).
Factory Method is similar to Abstract Factory but without the emphasis on families.
Factory Methods are routinely specified by an architectural framework, and then implemented by
the user of the framework.
Structure
The implementation of Factory Method discussed in the Gang of Four (below) largely overlaps
with that of Abstract Factory. For that reason, the presentation in this chapter focuses on the
approach that has become popular since.
An increasingly popular definition of factory method is: a static method of a class that returns an
object of that class' type. But unlike a constructor, the actual object it returns might be an
instance of a subclass. Unlike a constructor, an existing object might be reused, instead of a new
object created. Unlike a constructor, factory methods can have different and more descriptive
names (e.g.Color.make_RGB_color(float red, float green, float
blue) andColor.make_HSB_color(float hue, float saturation, float brightness)
The client is totally decoupled from the implementation details of derived classes. Polymorphic
creation is now possible.
Example
The Factory Method defines an interface for creating objects, but lets subclasses decide which
classes to instantiate. Injection molding presses demonstrate this pattern. Manufacturers of
plastic toys process plastic molding powder, and inject the plastic into molds of the desired
shapes. The class of toy (car, action figure, etc.) is determined by the mold.
o We are going to create a Plan abstract class and concrete classes that extends the Plan
abstract class. A factory class GetPlanFactory is defined as a next step.
o GenerateBill class will use GetPlanFactory to get a Plan object. It will pass information
(DOMESTICPLAN / COMMERCIALPLAN / INSTITUTIONALPLAN) to
GetPalnFactory to get the type of object it needs.
Step 2: Create the concrete classes that extends Plan abstract class.
class DomesticPlan extends Plan{
//@override
public void getRate(){
rate=3.50;
}
}//end of DomesticPlan class.
class CommercialPlan extends Plan{
//@override
public void getRate(){
rate=7.50;
}
/end of CommercialPlan class.
class InstitutionalPlan extends Plan{
//@override
public void getRate(){
rate=5.50;
}
/end of InstitutionalPlan class.
Step 4: Generate Bill by using the GetPlanFactory to get the object of concrete classes by
passing an information such as type of plan DOMESTICPLAN or COMMERCIALPLAN or
INSTITUTIONALPLAN.
import java.io.*;
class GenerateBill{
public static void main(String args[])throws IOException{
GetPlanFactory planFactory = new GetPlanFactory();
System.out.print("Enter the name of plan for which the bill will be generated: ");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String planName=br.readLine();
System.out.print("Enter the number of units for bill will be calculated: ");
int units=Integer.parseInt(br.readLine());
Plan p = planFactory.getPlan(planName);
//call getRate() method and calculateBill()method of DomesticPaln.
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Scanned by CamScanner
Download Useful Materials from Rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
System sequence diagrams - Relationship between sequence diagrams and use cases Logical
architecture and UML package diagram – Logical architecture refinement - UML class
diagrams - UML interaction diagrams - Applying GoF design patterns.
Sequence Diagram
Sequence Diagrams depict the objects and classes involved in the scenario and the
sequence of messages exchanged between the objects needed to carry out the
functionality of the system.
Sequence diagrams can be used to drive out testable user interface requirements.
: System
System Sequence Diagrams should be done for the main success scenario of the use-
case, and frequent and alternative scenarios.
Notations
Object:
:Object1
Actor: An Actor is modeled using the ubiquitous symbol, the stick figure.
actor 1
Lifeline: The LifeLine identifies the existence of the object over time. The notation for a
Lifeline is a vertical dotted line extending from an object.
www.rejinpaul.com
www.rejinpaul.com
messageName(argument)
Examples of SSD
Following example shows the success scenario of the Process Sale use case.
4. Optionally, include the use case text to the left of the diagram.
2. In the process Sale example, the customer does not directly interact with the POS
system. Cashier interacts with the system directly. Therefore cashier is the generator
of the system events.
System event
System operation
At this level, the design of a typical OO system is based on several architectural layers, such
as
UI layer
Application logic (or "domain") layer
Technical Service
Layers
Software Architecture
Software architecture is
the set of significant decisions about the organization of a software system,
the selection of the structural elements and their interfaces by which the system is
composed,
together with their behaviour as specified in the collaborations among those
elements, and
the composition of these structural and behavioral elements into progressively larger
subsystems.
www.rejinpaul.com
www.rejinpaul.com
// ---UI Layer
com.mycompany.nextgen.ui.swing
com.mycompany.nextgen.ui.web
// ---DOMAIN Layer
// packages specific to theNextGenproject
com.mycompany.nextgen.domain.sales
com.mycompany.nextgen.domain.payments
// ---TECHNICAL SERVICES Layer
// our home-grown persistence (database) access layer
com.mycompany.service.persistence
// third party
org.apache.log4j
org.apache.soap.rpc
// ---FOUNDATION Layer
// foundation packages that our team creates
com.mycompany.util
www.rejinpaul.com
www.rejinpaul.com
Model is a synonym for the domain layer of objects (it's an old OO term from the
late 1970s).
View is a synonym for UI objects, such as windows, Web pages, applets, and reports.
Principle:
Model (domain) objects should not have direct knowledge of view (UI) objects.
–E.g. Register or Sale objects should not directly send a message to a GUI window
object ProcessSaleFrame, asking it to display something, change color, close, and so
forth.
History:
Pattern Model-View-Controller (MVC) originally a small-scale Smalltalk-80 pattern.
The Model is the Domain Layer, the View is the UI Layer, and theControllers are the
workflow objects in the Application layer.
Layers
Information Systems
Layers
Software design is an iterative development, and it is normal to create a design of
layers that starts simple, and evolves over the iterations of the elaboration phase. It is
essential to have the core architecture established (designed and implemented) by the
end of the iterations in elaboration, but this does not mean doing a large up-front
speculative architectural design before starting to program. Rather, a tentative logical
architecture is designed in the early iterations, and it evolves incrementally through
the elaboration phase.
There are other types in these packages; only a few packages are shown to indicate
noteworthy aspects.
The Foundation layer was not shown in this view; the architect decided that it did
not add interesting information, even though the development team will certainly be
adding some Foundation classes, such as more advanced String manipulation utilities.
For now, a separate Application layer is not used. The responsibilities of control or
session objects in the Application layer are handled by the Register object. The
architect will add an Application layer in a later iteration as the behavior grows in
complexity, and alternative client interfaces are introduced (such as a Web browser
and wireless networked handheld PDA).
Applying UML:
www.rejinpaul.com
www.rejinpaul.com
Another common use of a package diagram is to hide the specific types, and focus on
illustrating the package-package coupling, as in the diagram given below.
the spirit of an “architectural view” which hides uninteresting details, and emphasizes
what the architect wants to convey, an interaction diagram in the logical view of the
architecture focuses on the collaborations as they cross layer and package boundaries. A
set of interaction diagrams that illustrate architecturally significant scenarios is thus
useful.
Applying UML:
The package of a type can optionally be shown by qualifying the type with the UML
path name expression <PackageName>::<TypeName>. For example,
Domain::Sales::Register. This can be exploited to highlight to the reader the inter-
package and inter-layer connections in the interaction diagram.
Note also the use of the «subsystem» stereotype. In the UML, a subsystem is a
discrete entity that has behavior and interfaces. A subsystem can be modeled as a
special kind of package, or—as shown here—as an object, which is useful when one
wants to show inter-subsystem (or system) collaborations. In the UML, the entire
www.rejinpaul.com
www.rejinpaul.com
system is also a “subsystem” (the root one), and thus can also be shown as an object
in interaction diagrams.
Note the use of the '1' in the top right corner to indicate a singleton, and suggest
access using the GoF Singleton pattern.
Information Systems
Information System (IS) is the most well-known examples of layered architecture.
o Method definitions
ProductDescription
SalesLineItem
description description : Text
quantity : Integer price : Money
1 itemID : ItemID
getSubtotal() : Money
...
www.rejinpaul.com
www.rejinpaul.com
{
ProductDescription desc = catalog.ProductDescription(id);
currentSale.makeLineItem(desc, qty);
}
1: desc := getProductDescription(id)
:Product
Catalog
Collection Class
What Collection classes has been added to the design and why?
Sale
public class Sale
{ isComplete : Boolean
... time : DateTime SalesLineItem
lineItems
private List lineItems = new ArrayList(); becomeComplete() quantity : Integer
1..*
} makeLineItem()
getSubtotal()
makePayment()
getTtotal()
Store
7
address : Address
1 2
name : Text
3 ProductDescription
ProductCatalog
addSale(...)
description : Text
... price : Money
1 1..* itemID : ItemID
getProductDesc(...)
...
1
1 Sale
5
6
Register isComplete : Boolean 4
time : DateTime SalesLineItem
...
becomeComplete() quantity : Integer
endSale() 1 1..*
makeLineItem(...)
enterItem(...) getSubtotal()
makePayment(...)
makeNewSale()
getTotal()
makePayment(...)
...
1
* Payment
amount : Money
1
...
class WorkPackage;
class Project;
class Activity;
class Task;
class WorkProduct;
www.rejinpaul.com
www.rejinpaul.com
class Resource;
class Skill;
class ResourceXSkill;
class WorkPackage
{ // Details omitted };
CollectionByVal<Task> theTask;
CollectionByRef<WorkProduct>
theWorkProduct; };
class Project
{ private:
char *Name;
char *Descr;
Date StartDate;
public:
aProject.setName (Name);
aProject.setDescr (Descr);
aProject.setStartDate (StartDate);
aProject.save (); }
www.rejinpaul.com
www.rejinpaul.com
Traditional systems define a unit as the smallest component that can be compiled and
executed.
Units are normally a component which in theory is only ever assigned to one
programmer.
Once a class is testing thoroughly it can be reused without being unit tested again.
UML class state charts can help with selection of test cases for classes.
Classes easily mirror units in traditional software testing
Classes obvious unit choice, but they can be large in some applications
Problems dealing with polymorphism and inheritance.
Composition Issues
Encapsulation Issues
Encapsulation requires that classes are only aware of their own properties, and are able to
operate independently.
If unit testing is performed well, the integration testing becomes more important.
If you do not have access to source code then structural testing can be impossible.
www.rejinpaul.com
www.rejinpaul.com
If you violate encapsulation for testing purposes, then the validity of test could be
questionable
Polymorphism Issues
Testing OO Code
Class Integration
tests tests
System Validation
tests tests
- Associate test case explicitly with the class and/or method to be tested
a. A list of messages and operations that will be exercised as a consequence of the test
c. A list of external conditions for setup (i.e., changes in the environment external to
the software that must exist in order to properly conduct the test)
Encapsulation:
o Each new context of use (subclass) requires re-testing because a method may
be implemented differently (polymorphism).
o Other unaltered methods within the subclass may use the redefined method
and need to be tested
o Basis path, condition, data flow and loop tests can all apply to individual
methods, but don’t test interactions between methods
www.rejinpaul.com
www.rejinpaul.com
Random testing - requires large numbers data permutations and combinations, and can
be inefficient
Example:
o An account class in a banking application has open, setup, deposit,
withdraw, balance, summarize and close methods
o The account must be opened first and closed on completion
o Open – setup – deposit – withdraw – close
o Open – setup – deposit –* [deposit | withdraw | balance | summarize] –
withdraw – close. Generate random test sequences using this template
Partition testing - reduces the number of test cases required to test a class
o state-based partitioning - tests designed in way so that operations that cause state
changes are tested separately from those that do not.
o attribute-based partitioning - for each class attribute, operations are classified
according to those that use the attribute, those that modify the attribute, and those
that do not use or modify the attribute
o category-based partitioning - operations are categorized according to the function
they perform: initialization, computation, query, termination
Fault-based testing
4. Integration Testing
OO does not have a hierarchical control structure so conventional top-down and bottom-
up integration tests have little meaning.
Kinds of integration testing:
big bang testing (5 facts) - An inappropriate approach to integration testing in which
you take the entire integrated system and test it as a unit
incremental testing (2 kinds, 3 facts) - A integration testing strategy in which you test
subsystems in isolation, and then continue testing as you integrate more and more
subsystems.
Integration applied three different incremental strategies:
o Thread-based testing: integrates classes required to respond to one input or
event
o Use-based testing: integrates classes required by one use case
o Cluster testing: integrates classes required to demonstrate one collaboration
Test case design becomes more complicated as integration of the OO system begins –
testing of collaboration between classes
Multiple class testing
o for each client class use the list of class operators to generate random test
sequences that send messages to other server classes
o for each message generated determine the collaborator class and the
corresponding server object operator
o for each server class operator (invoked by a client object message) determine the
message it transmits
o for each message, determine the next level of operators that are invoked and
incorporate them into the test sequence
o Use the state transition diagram (STD) as a model that represent the dynamic
behavior of a class.
www.rejinpaul.com
www.rejinpaul.com
Cluster Testing
Based on
o use cases
o corresponding sequence diagrams
Identify scenarios from use-cases and supplement these with interaction diagrams that
show the objects involved in the scenario
Concentrates on (functional) requirements
o Every use case
o Every fully expanded extension (<<extend>>) combination
o Every fully expanded uses (<<uses>>) combination
o Tests normal as well as exceptional behavior
www.rejinpaul.com
www.rejinpaul.com
5. GUI Testing
GUI testing is the process of ensuring proper functionality of the graphical user interface
(GUI) for a given application and making sure it conforms to its written specifications. In
addition to functionality, GUI testing evaluates design elements such as layout, colors, fonts,
font sizes, labels, text boxes, text formatting, captions, buttons, lists, icons, links and content.
GUI testing processes can be either manual or automatic, and are often performed by third -
party companies, rather than developers or end users. GUI testing can require a lot of
programming and is time consuming whether manual or automatic.
Command Line Interface is where you type text and computer responds to that
command.
GUI stands for Graphical User Interface where you interact with the computer using
images rather than text.
Following are the GUI elements which can be used for interaction between the user
and application:
In the below example, if we have to do GUI testing we first check that the images should be
completely visible in different browsers. Also, the links are available, and the button should
www.rejinpaul.com
www.rejinpaul.com
work when clicked. Also, if the user resizes the screen, neither images nor content should
shrink or crop or overlap.
A user doesn't have any knowledge about XYZ software/Application. It is the UI of the
Application which decides that a user is going to use the Application further or not. A normal
User first observes the design and looks of the Application/Software and how easy it is for
him to understand the UI. If a user is not comfortable with the Interface or find Application
complex to understand he would never going to use that Application Again. That's why, GUI
is a matter for concern, and proper testing should be carried out in order to make sure that
GUI is free of Bugs.
Check all the GUI elements for size, position, width, length and acceptance of characters
or numbers. For instance, you must be able to provide inputs to the input fields.
Check you can execute the intended functionality of the application using the GUI
Check Error Messages are displayed correctly
Check for Clear demarcation of different sections on screen
Check Font used in application is readable
Check the alignment of the text is proper
Check the Color of the font and warning messages is aesthetically pleasing
Check that the images have good clarity
Check that the images are properly aligned
Under this approach, graphical screens are checked manually by testers in conformance with
the requirements stated in the business requirements document.
GUI testing can be done using automation tools. This is done in 2 parts. During Record , test
steps are captured by the automation tool. During playback, the recorded test steps are
executed on the Application Under Test. Example of such tools - QTP .
www.rejinpaul.com
www.rejinpaul.com
The most common problem comes while doing regression testing is that the application GUI
changes frequently. It is very difficult to test and identify whether it is an issue or
enhancement. The problem manifests when you don't have any documents regarding GUI
changes.
6. System Testing
System Testing
– Black box
Functional Testing
Structure Testing
Acceptance Testing
Installation Testing
www.rejinpaul.com
www.rejinpaul.com
Functional Testing
Goal: Test functionality of system
• Test cases are designed from the requirements analysis document (better: user manual) and
centered around requirements and key functions (use cases)
• The system is treated as black box.
• Unit test cases can be reused, but new test cases have to be developed as well.
Structure Testing
Goal: Cover all paths in the system design
• Exercise all input and output parameters of each component.
• Exercise all components and all calls (each component is called at least once and every
component is called by all possible callers.)
• Use conditional and iteration testing as in unit testing.
Performance Testing
Goal: Try to break the subsystems
• Test how the system behaves when overloaded.
• Can bottlenecks be identified? (First candidates for redesign in the next iteration)
• Try unusual orders of execution
• Call a receive() before send()
• Check the system’s response to large volumes of data
• If the system is supposed to handle 1000 items, try it with 1001 items.
• What is the amount of time spent in different use cases?
• Are typical cases executed in a timely fashion?
o Recovery testing: how well and quickly does the system recover from faults
o Security testing: verify that protection mechanisms built into the system will protect
from unauthorized access (hackers, disgruntled employees, fraudsters)
o Volume testing: Test what happens if large amounts of data are handled
Acceptance Testing