Assignment No:-2: Object Oriented Analysis & Design

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Assignment No:-2

CAP-315
Object oriented Analysis
&
Design
Submitted to: Submitted by: Ankur Singh

Respected Ankur Singh


Akash Sir Roll no:- Re3801a29
Model Homework-2

Course Code:-CAP315

Course Title:- OBJECT ORIENTED ANALYSIS AND DESIGN

DOA: 11-02-2011 DOS: 22-02-2011

Part A

Q:-1 Differentiate between the terms Generalization and Specialization. Explain with
an example the close association between Generalization and Inheritance.

Ans 1

Generalization

Generalization uses a “is-a” relationship from a specialization to the generalization


class. Common structure and behaviour are used from the specializtion to the
generalized class. At a very broader level you can understand this as inheritance. Why
I take the term inheritance is, you can relate this term very well. Generalization is also
called a “Is-a” relationship.

Ankur Singh

specialization means creating new subclasses from an existing class. If it turns out that
certain attributes, associations, or methods only apply to some of the objects of the
class, a subclass can be created. The most inclusive class in a
generalization/specialization is called the superclass and is generally located at the
top of the diagram. The more specific classes are called subclasses and are generally
placed below the superclass.

Q:-2 Draw class diagram for the situation given below.

Ans 2.

A directory may contain many other directories and may optionally be contained in
other directory. Each directory has exactly one user who is the owner and many users
are authorized to use that directory. Respective classes must have their concerned
attributes and operations. Make necessary assumptions, if any.

Ankur Singh
Q:-3 What is association? Differentiate between 1-way and 2-way association
with example for each.

Ans 3

Association defines the relationship between two or more classes in the System. These
generally relates to the one object having instance or reference of another object
inside it. This article discusses on how we can implement Association in UML.

An association can be a one-way or two-way relationship. A one-way association


indicates the direction in which one can navigate from an object of one class to an
object of another class. A two-way association indicates bi-directional navigation
between objects of two classes.

In a one-way association, the first class has a reference to an object of the second class,
Ankur Singh

but the second class does not have a reference to an object of the first class. In a two-
way association, each class contains a reference to an object of the other class.
UML indicates a one-way association with an arrow at the end of the association line.
The attribute in the first class that contains a reference to an object of the second class
is also written at the end of the line.

For example, the following association indicates that an engine is part of a car:

A class can contain more than one association with another class. For example, the
following class diagram shows two associations between classes Flight and Pilot, one
association with the attribute pilot and another with the attribute coPilot:

Q:-4 Write a short note on Structural and Behavioural diagrams. What are the
constituent diagrams of these two broad categories? Discuss in brief, any two
constituent diagrams of each type.

Ans 4

 Structural diagrams are the most important and widely used part of UML. If you
say "UML", most people think of structural diagrams first.
 Structural diagrams are class diagrams and object diagrams
o Class diagrams represent the object-oriented code in your system. They
define all possible runs of the program.
o Object diagrams give specific examples of one possible run of the program
with specific data.
 Class diagrams can be used in requirements to express your understanding of
Ankur Singh

the real-world problem and to define the meaning of words you use in your
proposed solution. These diagrams do not use many of the details of the UML
notation.
 In design, class diagrams often have more detail and use more aspects of the
UML notation.
 Implementation may still diverge from design by adding more detailed
information. Not every detail of the implementation needs to be shown in the
design, but important aspects should be.
 A UML class corresponds to a Java class. A UML Interface corresponds to a Java
Interface. Every operation in an interface must be abstract.
 Classes and interfaces are drawn as boxes.
o The box can have up to three compartments
o The top compartment has the name of the class or interface
o Names of interfaces are marked "<<interface>>"
o Names of abstract classes are written in italics
o The lower to compartments are optional and contain attributes and
operations
 Each class can have instances when the program is run. The values of variables
in those instances must fit the types defined in the class.

Regular class: Abstract class: Interface:


ClassName ClassName InterfaceName
Attrbutes Attrbutes Attrbutes
Operations Operations Operations

Q:-5 Write short notes on any four:

(i) DFD and its features

Data flow diagrams illustrate how data is processed by a system in terms of


inputs and outputs.

Ankur Singh
FEATURES OF DATA FLOW DIAGRAM

1. All processes must have at least one data flow in and one data flow out.
2. All processes should modify the incoming data, producing new forms of
outgoing data.
3. Each data store must be involved with at least one data flow.
4. Each external entity must be involved with at least one data flow.
5. A data flow must be attached to at least one process.

(ii) Multiple Inheritance

Multiple Inheritance occurs when a class inherits from more than one parent.
For example, a person is a mammal and an intellectual entity, and a document
may be an editable item and a kind of literature.

(iii) Multiplicity and its type


Ankur Singh
(iv) 4+1 view of software architecture

Use-case view: Describes functionality of the system, its external interfaces,


and its principal users. This view is mandatory when using the 4+1 Views,
because all elements of the architecture should be derived from
requirements.

Logical view: Describes how the system is structured in terms of units of


implementation. The elements are packages, classes, and interfaces. The
relationship between elements shows dependencies, interface realizations,
part-whole relationships, and so forth. Note: This view is mandatory when
using the 4+1 Views of Software Architecture.

Implementation view: Describes how development artifacts are organized


in the file system. The elements are files and directories (any configuration
items). This includes development artifacts and deployment artifacts. This
view is optional when using the 4+1 Views.
Ankur Singh

Process view: Describes how the run-time system is structured as a set of


elements that have run-time behaviour and interactions. Run-time structure
often bears little resemblance to the code structure. It consists of rapidly
changing networks of communication objects. The elements are components
that have run-time presence (processes, threads, Enterprise JavaBeans™
(EJB™), servlets, DLLs, and so on), data stores, and complex connectors, such
as queues. Interaction between elements varies, based on technology. This
view is useful for thinking about run-time system quality attributes, such as
performance and reliability. This view is optional when using the 4+1 Views.

Deployment view: Describe how the system is mapped to the hardware.


This view is optional when using the 4+1 Views.

In addition, you may wish to represent the following,

Data view: A specialization of the logical view. Use this view if persistence is
a significant aspect of the system, and the translation from the design model
to the data model is not done automatically by the persistence mechanism.

(v) Mapping object classes and association to tables

to property and inheritance mapping you need to understand the art of


relationship mapping. There are three types of object relationships that you
need to map: association, aggregation, and composition. For now, I’m going
to treat these three types of relationship the same – they are mapped the
same way although there are interesting nuances when it comes to
referential integrity.

There are two categories of object relationships that you need to be


concerned with when mapping. The first category is based on multiplicity
and it includes three types:

 One-to-one relationships. This is a relationship where the maximums of each


of its multiplicities is one, an example of which is holds relationship between
Employee and Position. An employee holds one and only one position and a
position may be held by one employee (some positions go unfilled).
 One-to-many relationships. Also known as a many-to-one relationship, this
Ankur Singh

occurs when the maximum of one multiplicity is one and the other is greater
than one. An example is the works in relationship between Employee and
Division. An employee works in one division and any given division has one or
more employees working in it.
 Many-to-many relationships. This is a relationship where the maximum of
both multiplicities is greater than one, an example of which is the assigned
relationship between Employee and Task. An employee is assigned one or more
tasks and each task is assigned to zero or more employees.

The second category is based on directionality and it contains two types, uni-
directional relationships and bi-directional relationships.

 Uni-directional relationships. A uni-directional relationship when an object


knows about the object(s) it is related to but the other object(s) do not know of
the original object. An example of which is the holds relationship between
Employee and Position in, indicated by the line with an open arrowhead on it.
Employee objects know about the position that they hold, but Position objects
do not know which employee holds it (there was no requirement to do so). As
you will soon see, uni-directional relationships are easier to implement than bi-
directional relationships.
 Bi-directional relationships. A bi-directional relationship exists when the
objects on both end of the relationship know of each other, an example of which
is the works in relationship between Employee and Division. Employee objects
know what division they work in and Division objects know what employees
work in them.

Part B

Q:-6 Differentiate:

(i) Aggregation and Generalization

 Association is a (*a*) relationship between two classes, where one class use
another. But aggregation describes a special type of an association. Aggregation
is the (*the*) relationship between two classes. When object of one class has an
(*has*) object of another, if second is a part of first (containment relationship)
then we called that there is an aggregation between two classes. Unlike
Ankur Singh

association, aggregation always insists a direction.


In this case I can say that University aggregate Chancellor or University has an
(*has-a*) Chancellor. But even without a Chancellor a University can exists. But
the Faculties cannot exist without the University, the life time of a Faculty (or
Faculties) attached with the life time of the University . If University is disposed
the Faculties will not exist. In that case we called that University is composed of
Faculties. So that composition can be recognized as a special type of an
aggregation.

Same way, as another example, you can say that, there is a composite
relationship in-between a KeyValuePairCollection and a KeyValuePair. The two
mutually depend on each other.

.Net and Java uses the Composite relation to define their Collections. I have seen
Composition is being used in many other ways too. However the more important
factor, that most people forget is the life time factor. The life time of the two
classes that has bond with a composite relation mutually depend on each other.
If you take the .net Collection to understand this, there you have the Collection
Element define inside (it is an inner part, hence called it is composed of) the
Collection, farcing the Element to get disposed with the Collection. If not, as an
example, if you define the Collection and it’s Element to be independent, then
the relationship would be more of a type Aggregation, than a Composition. So
the point is, if you want to bind two classes with Composite relation, more
Ankur Singh

accurate way is to have a one define inside the other class (making it a protected
or private class). This way you are allowing the outer class to fulfil its purpose,
while tying the lifetime of the inner class with the outer class.
So in summary, we can say that aggregation is a special kind of an association
and composition is a special kind of an aggregation.

(Association->Aggregation->Composition)

(ii) Aggregation and Association

An Association is a channel between classes through which messages can be sent. As


sending messages translates to calling methods in Java, Associations are typically (but
not necessarily) implemented by references.

An Aggregation is an Association which denotes an "is part of" relationship.


Unfortunately, the definition of this relationship is quite lax, so basically everyone is
using his own interpretation. The only definitive (?) property is that in an instance
graph, aggregations are not allowed to be circular - that is, an object cannot be "a part
of itself". (Or) When building new classes from existing classes using aggregation, a
composite object built from other constituent objects that are its parts. Java supports
aggregation of objects by reference, since objects can't contain other objects explicitly.

(iii) Good design and Bad design


Ankur Singh

Good Design

Designing software is not the same as creating nice UML diagrams. I know a lot of
programs that have beautiful UML diagrams but are terribly bad designed. On the
other hand, some of the most interesting architectures were not created from an UML
diagram. From a pragmatic perspective, having a good design means that the resulting
architecture provides the basic mechanisms for extending the original program
without the need to rewrite its basic components.

In a well design program, developers can feel confident to extend the system, without
thinking that they need to understand something very subtle about its internals. For
example, very few people need to know how UNIX is internally implemented in order
to write a new application.

Bad Design

A badly designed piece of software can have growing costs that will continue forever
as long as changes are necessary. If there is any need for extension in such a system,
then one has to understand how each piece works together. Working in this way is like
playing with a house of cards: for lack of a foundation, any change in the system can
bring the whole thing down.

Q:-7 How do we implement the concept of association in C++/Java?

Ans 7

Association specifies how objects are related to one another.To identify


associations,look for verb and prepositional phrases like 'part of','next to','works for'
or 'contained in'.While identifying implicit associations,a lot common sense and
general knowledge is required.It is very important to eleminate redundant
associations while desiging a system.The most important aspects of associations are:
Cardinality - a cardinality of one on a given relationship end generates a Java
reference, for example

Q:-8 How do you show instantiation in a UML Sequence Diagram?

Ans 8

Sequence diagrams are used to model the logic of usage scenarios. A usage scenario is
Ankur Singh

exactly what its name indicates -- the description of a potential way your system is
used. The logic of a usage scenario may be part of a use case, perhaps an alternate
course. It may also be one entire pass through a use case, such as the logic described
by the basic course of action or a portion of the basic course of action, plus one or
more alternate scenarios. The logic of a usage scenario may also be a pass through the
logic contained in several use cases. For example, a student enrolls in the university,
and then immediately enrolls in three seminars. Sequence diagrams model the flow of
logic within your system in a visual manner, enabling you to both document and
validate your logic, and are commonly used for both analysis and design purposes.

Q:-9 Create an activity diagram and a use case model (complete with a set of
detail use case descriptions) for the above system. Produce an initial domain
model (class diagram) based on these descriptions. Elaborate the use cases into
sequence diagrams, and include any state diagrams necessary. Finally use the
information from these dynamic models to expand the domain model into a full
application model.

Ans 9

Q:-10 What would be the best UML diagram to show decoupling of two
multithreaded classes, joined by a producer consumer queue.

Ans 10
Ankur Singh

The gap between the speeds of processors and memories has kept increasing in the
past decade and it is expected to sustain the same trend in the near future. This
divergence implies, in terms of clock cycles, an increasing latency of those memory
operations that cross the chip boundaries. In addition, processors keep on growing
their capabilities to exploit parallelism by means of greater issue widths and deeper
pipelines, which makes even higher the negative impact of memory
latencies on performance. To alleviate this problem, most current processors devote a
high fraction of their transistors to on-chip caches, in order to reduce the average
memory access time.

Some processors, commonly known as out-of-order processors include


dynamic scheduling techniques, most of them based on Tomasulo's algorithm or
variations of it. These processors tolerate both memory and functional unit latencies
by overlapping them with useful computations of other independent instructions,
which are found by looking ahead in the instruction stream, inside a limited
instruction window. This is a general scheduling mechanism that dynamically extracts
the instruction parallelism available in the instruction window.

As memory latency continues to grow in the future, out-of-order processors will need
larger instruction windows to find independent instructions to fill the increasing
number of empty issue slots, and this number will grow even faster with greater issue
widths. The increase in the instruction window size will have an obvious influence on
the chip area, but its major negative impact will strike at the processor clock cycle
time

Ankur Singh

You might also like