0% found this document useful (0 votes)
150 views40 pages

OOAD Unit-2

The document discusses structural modeling in object-oriented analysis and design using UML class diagrams, including how to model classes, attributes, methods, and relationships between classes such as association, aggregation, generalization, and dependency. It provides examples of class diagrams for modeling vocabulary of a class using the Person class as an example, and relationships using associations between Account and Customer classes in a banking system.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
150 views40 pages

OOAD Unit-2

The document discusses structural modeling in object-oriented analysis and design using UML class diagrams, including how to model classes, attributes, methods, and relationships between classes such as association, aggregation, generalization, and dependency. It provides examples of class diagrams for modeling vocabulary of a class using the Person class as an example, and relationships using associations between Account and Customer classes in a banking system.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 40

20CS3221-Object Oriented Analysis and Design

Mallikarjuna Nandi
Assistant Professor
Computer Science & Engineering
RGUKT- Ongole-AP

02/22/2024 RGUKT Ongole Campus 1


Unit 2- Syllabus

Unit – II (Basic Structural Modeling) (9 Contact hours)

Classes, Relationships, Common Mechanisms, and diagrams.


Advanced Structural Modeling: Advanced classes, advanced relationships,
Interfaces, Types and Roles, Packages.

02/22/2024 RGUKT Ongole Campus 2


UNIT-2

Structural modeling in UML (Unified Modeling Language) is a type of modeling that focuses on the static
structure of a system or software application. It is used to describe the components of a system and their
relationships, as well as the constraints and interfaces that govern how they interact with each other.
Diagrams are:
 Class diagram
 Object diagram
 Deployment diagram
 Component diagram

Structural modeling is useful for understanding the architecture and design of a software system, as well as
for communicating that information to stakeholders and team members. It is designed in a way that meets
the requirements and is scalable, maintainable, and extensible.

02/22/2024 RGUKT Ongole Campus 3


UNIT-2

Class diagrams: These diagrams are used to represent the classes in a system and the relationships
between them. A class is a template or blueprint for creating objects, and it defines the properties and
methods that objects of that class will have. A class diagram consists of:

Class: A class represents a template for creating objects that share the same attributes,
operations, relationships, and behavior. It is represented as a rectangle with the class name
written inside it.
Attributes: Attributes are the data members of a class. They describe the characteristics of
the objects created from the class. They are represented as name: type pairs in the class
rectangle.
Methods: Methods are the operations that can be performed on the objects created from the
class. They are represented as name(parameter list):return type in the class rectangle.

02/22/2024 RGUKT Ongole Campus 4


UNIT-2

The vocabulary of a class can be modeled using the attributes and operations of the class. The attributes
represent the properties or characteristics of the objects that belong to the class, while the operations
represent the actions or behaviors that the objects can perform. Here are some guidelines for modeling the
vocabulary of a class in UML:
Identify the key properties of the class: The key properties of a class are the attributes that define its
identity or differentiate it from other classes. For example, if you are modeling a class for a person, the key
properties could include the person's name, age, gender, and occupation.

Identify the operations that the objects can perform: The operations of a class are the functions or
methods that the objects can perform. For example, if you are modeling a class for a person, the operations
could include walking, talking, eating, sleeping, and working.

02/22/2024 RGUKT Ongole Campus 5


UNIT-2

Use relationships to model associations between classes: Classes can have associations with other classes,
such as composition, aggregation, or inheritance. You can use UML relationships (represented by lines and
symbols) to model these associations.
Person
In this example, the class is called Person and has four attributes: name (a
-name: String
string), age (an integer), gender (a string), and occupation (a string). The -age: Integer
attributes are marked as private (-) to indicate that they can only be accessed by -gender: String

methods within the class. -Occupation: String

The class has four methods: walk (which takes an integer parameter and returns +walk(distance: Integer): Void
+talk(message: String): Void
void), talk (which takes a string parameter and returns void), eat (which takes a
+eat(food: String): Void
string parameter and returns void), and sleep (which takes an integer parameter
+sleep(hour: Integer): Void
and returns void). The methods are marked as public (+) to indicate that they can
be accessed by other classes.

02/22/2024 RGUKT Ongole Campus 6


UNIT-2

Relationships: Relationships represent the associations between the classes, such as inheritance,
composition, aggregation, and association. They are represented as lines between the classes with an
arrowhead indicating the direction of the relationship.
Class diagrams are useful for modeling the relationships between different objects and classes in a
system, and they can help in identifying potential issues in the design of a system.

Relationships demonstrates how things are interrelated to


each other at the time of system execution. It constitutes
four types of relationships, i.e., dependency, association,
generalization, and realization.

02/22/2024 RGUKT Ongole Campus 7


UNIT-2
The main types of relationships are:
1. Association: An association relationship represents a connection between two classes, indicating that
instances of one class are related to instances of another class. Consider a banking system that has two
classes, Account and Customer. Each account is associated with a customer.

The association between the Account and Customer classes can be labeled as "has" or
"belongs to", indicating that an account "belongs to" a customer. The association can also be given a
multiplicity, which specifies the number of instances that can participate in the association.
For example, the multiplicity on the Customer side of the association may be "1..*", indicating that
each customer can have zero or more accounts, while the multiplicity on the Account side may be "1",
indicating that each account must be associated with exactly one customer.
02/22/2024 RGUKT Ongole Campus 8
UNIT-2

Multiplicity is a concept used to specify how many objects can participate in a relationship between two
classes. Multiplicity is represented using numbers or special symbols near the association line between two
classes.
One-to-one relationship: In a one-to-one relationship, each instance of one class is associated with one
and only one instance of another class. This is represented by the number "1" on each end of the association
line.
One-to-many relationship: In a one-to-many relationship, each instance of one class is associated with
one or more instances of another class. This is represented by the number "1" on one end of the association
line, and the asterisk symbol (*) on the other end.
Many-to-many relationship: In a many-to-many relationship, each instance of one class is associated with
one or more instances of another class, and vice versa. This is represented by the asterisk symbol (*) on both
ends of the association line.
02/22/2024 RGUKT Ongole Campus 9
UNIT-2
Aggregation is a relationship between two classes where one class (the containing class) contains instances
of another class (the contained class). Aggregation is typically shown with a diamond symbol at the end of
the association line pointing towards the class that contains the instances.
Aggregation implies a relationship where the child can exist independently of the
parent. Example: Class (parent) and Student (child). Delete the Class and the Library
Students still exist. +name: string
+address: string
+books: Book [ ]

Example: we are designing a library management system, and we have two classes:
Library and Book. The Library class contains a collection of books, so we can represent this
relationship using aggregation. The Library class is the containing class, and the Book class
Book
is the contained class.
+title : string
+author : string
In the example, the Library class contains an array of Book objects, which are instances +ISBN : String
of the Book class. The aggregation relationship is shown with a diamond symbol on the
association line connecting the two classes, with the symbol pointing towards the Library
class, indicating that it is the containing class.

02/22/2024 RGUKT Ongole Campus 10


UNIT-2

Aggregation is a specialised form of association. It defines a one-way relationship that specifies a 'has-a'
relationship between two classes. For example, you can say that a wallet has money. However, the money
does not need a wallet in order to exist, so the relationship is one-way.

02/22/2024 RGUKT Ongole Campus 11


UNIT-2

Composition relationship is a type of association where one class (the "whole" or composite object)
contains another class (the "part" or component object) as a part.

The composition association relationship connects the Person class with Brain class, Heart class, and Legs
class. If the person is destroyed, the brain, heart, and legs will also get discarded.

Combination of aggregation and composition is called whole/part Relationship

02/22/2024 RGUKT Ongole Campus 12


UNIT-2
Association Aggregation Composition
Association relationship is Aggregation relationship is represented by The composition relationship is represented
represented using an arrow. a straight line with an empty diamond at by a straight line with a black diamond at one
one end. end.

In UML, it can exist between It is a part of the association relationship. It is a part of the aggregation relationship.
two or more classes.
It can associate one more In an aggregation relationship, the In a composition relationship, the associated
objects together. associated objects exist independently objects cannot exist independently within the
within the scope of the system. scope of the system.

It may or may not affect the Deleting one element in the aggregation It affects the other element if one of its
other associated element if relationship does not affect other associated element is deleted.
one element is deleted. associated elements.

Example: A tutor can associate Example: A car needs a wheel for its Example: If a file is placed in a folder and
with multiple students, or one proper functioning, but it may not require that is folder is deleted. The file residing
student can associate with the same wheel. It may function with inside that folder will also get deleted at the
multiple teachers. another wheel as well. time of folder deletion.

02/22/2024 RGUKT Ongole Campus 13


UNIT-2

Dependency is an important aspect in UML elements. It describes the dependent elements and the
direction of dependency. Dependency is represented by a dotted arrow . The arrow head represents the
independent element and the other end represents the dependent element.

02/22/2024 RGUKT Ongole Campus 14


UNIT-2

Generalization describes the inheritance relationship of the object-oriented world. It is a parent and child
relationship. Generalization is represented by an arrow with a hollow arrow head . One end represents the
parent element and the other end represents the child element. Generalization is used to describe parent-
child relationship of two elements of a system.

02/22/2024 RGUKT Ongole Campus 15


UNIT-2

02/22/2024 RGUKT Ongole Campus 16


UNIT-2

1. Find the Unique domain Class:


2. Draw the class diagram of each domain class
3. Showing relationship

02/22/2024 RGUKT Ongole Campus 17


UNIT-2

02/22/2024 RGUKT Ongole Campus 18


UNIT-2
Online Shopping System:
Draw a class diagram for an online shopping system. Include classes such as Product, Customer, and Order.
Specify relationships and attributes.
School Management System:
Create a class diagram for a school management system. Include classes like Student, Teacher, and Course.
Indicate associations, multiplicities, and relevant attributes.
Social Media Platform:
Design a class diagram for a social media platform. Consider classes like User, Post, and Comment. Specify the
relationships between these classes.
Hospital Management System:
Draw a class diagram for a hospital management system. Include classes such as Patient, Doctor, and
Appointment. Define the associations and attributes.
Library Catalog System:
Develop a class diagram for a library catalog system. Incorporate classes like Book, Author, and Library. Define
associations, attributes, and multiplicity.

02/22/2024 RGUKT Ongole Campus 19


UNIT-2 (Advanced Structural Modeling)

Advanced Class
A class is defined using the class keyword where c of class is in small case.

Once a class is defined, instances (objects) of the class can be created and each instance
can have different copy of instance variables (attributes/fields).

The data fields described inside the class are the properties and methods of the object.
These data fields are created when ever an object of the class is instantiated.

Method declaration has four parts:


Method Name
Data Type of the value returned by the method
List of parameters being passed to the method
Instructions inside the method

02/22/2024 RGUKT Ongole Campus 20


UNIT-2

Advanced Class
The Constructor enables an object to initialize itself when it is created they have
the same name as the class they do not have any return type not even a void

02/22/2024 RGUKT Ongole Campus 21


UNIT-2

Operators and Methods

All operations and methods are also properties of the class usually it is mentioned in the
third compartment of the class.

It also describes all arguments required for the method.It also describes the return data
type of the method. Generally it is mentioned in class diagram not in object diagram.

Sometimes you need to mention static and dynamic methods also. They may also has
access specifiers like packages, private, protected, public.

02/22/2024 RGUKT Ongole Campus 22


UNIT-2

Classifier : A classifier is a mechanism that has structural features (in thevform of attributes), as well as
behavioral features (in the form of operations). Classifiers include classes, interfaces, datatypes, signals,
components, nodes, use cases, and subsystems. Those modeling elements that can have instances are called
classifiers. Every instance of a given classifier shares the same features. The most important kind of classifier
in UML is class.

02/22/2024 RGUKT Ongole Campus 23


UNIT-2

Classifiers :
1. Interface A collection of operations that are used to specify a service of a class or a component.

2. Datatype A type whose values are immutable, including primitive built-in types (such as numbers and
strings) as well as enumeration types (such as Boolean)
3. Collaboration (Signal): defines an interaction between elements.

02/22/2024 RGUKT Ongole Campus 24


UNIT-2

4. Use case represents a set of actions performed by a system for a specific goal.

5. Node: A node can be defined as a physical element that exists at run time.

6. Component describes the physical part of a system.

02/22/2024 RGUKT Ongole Campus 25


UNIT-2
Visibility
One of the design details you can specify for an attribute or operation is visibility. The visibility of a
feature specifies whether it can be used by other classifiers. In the UML, you can specify any of four levels
of visibility.
1. Public: Any outside classifier with visibility to the given classifier can use the feature; specified by
the symbol +. .
2. private: Only the classifier itself can use the feature; specified by prepending the symbol -.
3. package: Only classifiers declared in the same package can use the feature; specified by the symbol ~.

02/22/2024 RGUKT Ongole Campus 26


UNIT-2

Advanced Relationships

Enumeration : The enumeration relationship allows us to represent a set of related constant values (days of
the week) within the context of a class that has an attribute associated with that enumeration type.
-----------------
Dependency
Association
 Aggregation
 Composition
Generalization
Realization

02/22/2024 RGUKT Ongole Campus 27


UNIT-2

Abstract class is a class that cannot be created and serves as a base or parent class for other classes. It provides a way to
define common properties and behavior that can be shared among multiple classes. Abstract classes typically contain
one or more abstract methods, which are methods without an implementation that must be implemented by subclasses.

Example, the class "Animal" is an abstract class because it has the


<<abstract>>
"<<abstract>>" stereotype. This means that it cannot be created directly, but can Animal
only be used as a base class for other classes. The class has a property "name" of Name : string
type String, which is common to all animals. It also has an abstract method
"makeSound()", which must be implemented by any subclass that wants to Makesound()
inherit from the "Animal" class.

02/22/2024 RGUKT Ongole Campus 28


UNIT-2
Example, a subclass "Dog" can inherit from the "Animal" class and implement the "makeSound()" method as follows:

In this example, the class "Dog" inherits from the "Animal" class and implements the
<<abstract>>
"makeSound()" method. It also has a property "breed" of type String, which is specific
Animal
to dogs.
Name : string
By using an abstract class in this way, we can create a common structure for all
animals, while still allowing for the unique characteristics of each specific animal
Makesound()
subclass.

we have an abstract class called as a motion with a method or an operation declared


inside of it. The method declared inside the abstract class is called a move (). dog
This abstract class method can be used by any object such as a car, an animal, robot,
Breed : string
etc. for changing the current position. It is efficient to use this abstract class method
Makesound()
with an object because no implementation is provided for the given function. We can
use it in any way for multiple objects.
02/22/2024 RGUKT Ongole Campus 29
UNIT-2

Interface: is a type of element that defines a set of operations that can be implemented by any class or
component that adopts the interface.
Example: we are designing a system for managing different types of vehicles, including cars, buses, and
trucks. We want to define a set of operations that each vehicle type must support, such as "start", "stop",
"accelerate", and "decelerate". we can define an interface called "IVehicle" that specifies these operations.

This interface specifies a set of operations that every vehicle must


Ivehicle
implement. For example, a car, a bus, and a truck would each provide their
own implementation of these operations. Start()
Stop()
we can define a set of classes that represent different vehicle types. Each of
Accelerate ()
these classes would implement the "IVehicle" interface, which would ensure
Decelerate()
that they all provide the same set of operations.

02/22/2024 RGUKT Ongole Campus 30


UNIT-2

Packages are used to organize elements into groups, making it easier to manage and understand complex
systems. Advanced structural modeling with packages allows software engineers to model the organization
and structure of a system, including its components, classes, interfaces, and other elements.
Here are some examples of how packages can be used in advanced structural modeling:
Organizing Classes and Interfaces: Packages can be used to organize classes and interfaces into logical
groups. For example, all the classes and interfaces related to user management can be grouped into a
package called "User Management." This makes it easier to understand the overall structure of the system
and find the relevant classes and interfaces.
Representing Layers: Packages can be used to represent layers in a system. For example, the presentation
layer, business logic layer, and data access layer can each be represented as a separate package. This makes
it easier to manage the layers independently and to understand the dependencies between them. (CUSTMER
LAYER, MANAGER LAYER ETC)
02/22/2024 RGUKT Ongole Campus 31
UNIT-2

Separating Concerns: Packages can be used to separate concerns within a system. For example, all the
classes related to logging can be grouped into a package called "Logging." This separates the logging
functionality from other parts of the system and makes it easier to modify or replace the logging component.

Representing Subsystems: Packages can be used to represent subsystems within a larger system. For
example, a system that includes multiple modules or components can be represented using packages to group
related elements together. This makes it easier to manage and understand the system as a

02/22/2024 RGUKT Ongole Campus 32


UNIT-2

ATM Transaction

02/22/2024 RGUKT Ongole Campus 33


UNIT-2

Food ordering System

02/22/2024 RGUKT Ongole Campus 34


UNIT-2

Railway Reservation System

02/22/2024 RGUKT Ongole Campus 35


Passport Management System

02/22/2024 RGUKT Ongole Campus 36


CREDIT CARD PROCESSING

02/22/2024 RGUKT Ongole Campus 37


CONFERENCE MANAGEMENT SYSTEM

02/22/2024 RGUKT Ongole Campus 38


1. Write the four kinds of relationships available in the UML
2. Draw the class diagram for stock maintenance system.
3. Write the features that distinguish sequence diagrams from collaboration diagrams.
4. Draw the use case diagram for online railway reservation system.
5. Draw the component diagram for Aadhar management system.
Thank You

02/22/2024 RGUKT Ongole Campus 40

Common questions

Powered by AI

In UML, dependency and association relationships are differentiated to clarify class interactions. Dependency, represented by a dotted arrow, indicates a temporary relationship where one class relies on another for specific functionality, without a direct or lasting ownership link . Association, however, is denoted by a solid line and represents a stronger connection where classes are aware of each other and may potentially influence each other's state . These distinctions help designers articulate and manage the degree of coupling between classes, influencing how changes affect system components, and clarifying relationship dynamics in design diagrams .

Abstract classes in UML serve as templates for other classes to extend and are marked by the stereotype '<<abstract>>'. They cannot be instantiated directly but define common characteristics and abstract methods to be implemented by subclasses . Inheritance allows subclasses to inherit properties and behaviors defined in the abstract class, facilitating code reuse. Abstract classes support polymorphism, enabling objects to be treated as instances of their parent class type, thus allowing diverse classes to be interacted with uniformly through a shared interface defined by their abstract class .

In UML, multiplicity specifies the number of instances that can participate in a relationship between two classes. It is denoted using numbers or symbols on the association line between classes. For example, a one-to-one relationship uses '1:1', indicating a single instance of one class relates to exactly one instance of another. A one-to-many relationship uses '1:*', indicating a single instance of one can associate with many instances of another. Many-to-many uses '*:*' for multiple associations between both classes . Impacts on system design include influencing how data structures are modeled and constraints are managed in the system, ensuring accurate mapping of real-world requirements to object relationships .

UML utilizes visibility symbols to control access to class members, contributing to encapsulation in software architecture. Public visibility, denoted by '+', allows access by any outside classifier. Private visibility, denoted by '-', restricts access to within the classifier itself. Package visibility, represented by '~', allows access within the same package. Protected is indicated although not listed, allowing access to subclasses . These visibility modifiers are crucial for safeguarding data integrity and promoting modular design through controlled interactions, thereby influencing the maintainability and scalability of the software system .

In UML, associations represent relationships between classes, indicating how many objects of each class can participate in the relationship. Associations can have names, roles, and multiplicity constraints to define interaction specifics . For example, in a library management system, a 'Library' class can be associated with a 'Book' class. Here, the Library class may have an aggregation relationship with the Book class, indicating that a library contains multiple books, but the existence of a book is independent of the library . This practical use in system design clarifies whether objects are shared or exist independently, affecting memory management and data modeling .

In UML, aggregation and composition both represent 'whole-part' relationships but differ in lifecycle dependency. Aggregation implies a relationship where the 'child' can exist independently of the 'parent'; deletion of the parent does not affect the child, as seen with a classroom and student relationship . In contrast, composition implies a strict lifecycle dependency where the 'child' cannot exist without the 'parent'; if the parent is deleted, so are its children, such as a house and its rooms . These concepts impact lifecycle management by dictating how object dependencies are maintained, affecting resource management policies in software design .

UML represents generalization through an arrow with a hollow arrowhead directed from a child to a parent class . This relationship is equivalent to inheritance in object-oriented programming. It allows a child class to inherit attributes and methods from the parent class, promoting reusability and reducing redundancy. The design of hierarchical class structures using generalization facilitates common interfaces among classes, simplifies maintenance, and enhances code manageability by organizing classes into a clear, scalable hierarchy .

Advanced structural modeling with packages in UML offers several advantages by organizing elements into coherent groups . They enhance system clarity and manageability by categorizing classes, interfaces, and other elements into separated entities, such as layers or subsystems, which reflect logical divisions within the architecture. This approach simplifies system understandability and navigation, supports modular development practices, and aids in managing dependencies more effectively. Packages facilitate concern separation, allowing teams to focus on specific system parts, which improves collaboration and streamlines development and maintenance processes .

Class diagrams hold significant importance in system modeling by visually representing the static structure of a system, focusing on classes, their attributes, operations, and the relationships among entities . They aid in understanding the software architecture by providing an unambiguous depiction of the system's components and their interactions. Class diagrams help identify and visualize potential design issues, facilitate communication between stakeholders, and serve as a blueprint during system development. They enable effective planning and assessment of architectural decisions, thus impacting the design's robustness and consistency .

Interfaces in UML facilitate behavioral abstraction by defining a contract for operations without specifying their execution details, represented by the 'interface' stereotype . They enable different classes to implement shared behavior in their manner, supporting polymorphism. In a typical software system, interfaces play a critical role by allowing developers to decouple the specification of operations from their implementation. This leads to flexible systems where behavior can be extended and modified with minimal changes to existing code, thereby fostering maintainability and accommodating future changes or scaling .

You might also like