0% found this document useful (0 votes)
10 views5 pages

Ooad Notes

Uploaded by

jadeanica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Ooad Notes

Uploaded by

jadeanica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

A class diagram is a type of static structure diagram in UML (Unified Modeling Language) that

represents the classes, their attributes, methods, and the relationships among them within a
system. It provides a visual overview of the system's architecture and helps in understanding how
different entities interact.

Components of a Class Diagram

1. Classes:
o Represented as rectangles divided into three sections:
▪ Name: The class name at the top.
▪ Attributes: The middle section lists the properties of the class.
▪ Methods: The bottom section lists the functions or operations the class
can perform.
2. Attributes:
o Properties or data fields of a class, typically defined with visibility (public,
private, protected), type, and name (e.g., +name: String).
3. Methods:
o Functions or operations that can be performed by the class, often also defined
with visibility, return type, and parameters (e.g., +getName(): String).
4. Relationships:
o Associations: Represents a relationship between classes. Can be unidirectional or
bidirectional.
o Multiplicity: Indicates how many instances of a class can be associated with
instances of another class (e.g., one-to-many).
o Inheritance: Represented with a solid line and a hollow triangle, indicating that
one class (subclass) inherits from another (superclass).
o Aggregation: A whole-part relationship, depicted with a hollow diamond at the
whole end.
o Composition: A stronger form of aggregation where the part cannot exist
independently of the whole, depicted with a filled diamond.
5. Interfaces:
o Represented like classes but often distinguished by stereotypes (e.g.,
<<interface>>). They define a contract that implementing classes must fulfill.
6. Packages:
o Used to group related classes and can be represented as a folder icon, helping in
organizing large diagrams.
Visibility in class diagrams is crucial as it defines the accessibility of class attributes and
methods from other classes. This encapsulation principle is fundamental in object-oriented
design, promoting modularity and security. Here's a breakdown of the significance of visibility:

Types of Visibility

1. Public (+):
o Members (attributes/methods) marked as public can be accessed from any other
class. This is useful for methods that need to be widely available, such as user-
facing functions.
2. Private (-):
o Private members can only be accessed within the class itself. This protects the
internal state of the object, preventing outside interference and ensuring that the
object's integrity is maintained.
3. Protected (#):
o Protected members are accessible within the class and by subclasses. This allows
for controlled access in inheritance scenarios, enabling subclasses to leverage
certain functionalities without exposing them to the rest of the system.
4. Package (~) (not always used):
Package visibility allows access to members within the same package.
This is often seen in larger systems organized into packages or modules.

In UML (Unified Modeling Language), dependencies between packages are represented using
dependency arrows. Here’s how this works:

Dependency Representation

1. Dependency Arrow:
o A dependency is shown with a dashed line (or dotted line) that points from the
dependent package to the package it depends on.
o The arrowhead indicates the direction of the dependency, meaning the package at
the arrowhead is the one that is being depended upon.
2. Notation:
o The line typically appears as ---------> with a dashed line leading to the
package that is being depended on.
o You can also add a label to the dependency line to clarify the nature of the
dependency (e.g., "uses", "calls", or "requires").

Example

Here’s a simple textual representation of two packages, OrderProcessing and


PaymentProcessing, where OrderProcessing depends on PaymentProcessing:

+---------------------+ +----------------------+
| OrderProcessing |-------->| PaymentProcessing |
+---------------------+ +----------------------+
In a class diagram, relationships between classes illustrate how classes interact with one another.
Understanding these relationships is essential for modeling the structure of a system. Here are
the primary types of relationships commonly found in class diagrams:

1. Association

• Definition: A basic relationship where one class uses or interacts with another class.
• Notation: A solid line connecting the classes.
• Multiplicity: Indicates how many instances of one class can be associated with instances
of another class (e.g., one-to-one, one-to-many).
• Example: A Customer can place multiple Orders, indicating a one-to-many association.

2. Aggregation

• Definition: A specialized form of association that represents a "whole-part" relationship,


where the part can exist independently of the whole.
• Notation: A solid line with a hollow diamond at the whole end.
• Example: A Library contains multiple Books, but a Book can exist without a Library.

3. Composition

• Definition: A stronger form of aggregation where the part cannot exist independently of
the whole. If the whole is destroyed, so are the parts.
• Notation: A solid line with a filled diamond at the whole end.
• Example: A House is made up of Rooms, and if the House is destroyed, the Rooms no
longer exist.

4. Inheritance (Generalization)

• Definition: A relationship where one class (subclass) inherits attributes and methods
from another class (superclass).
• Notation: A solid line with a hollow triangle pointing to the superclass.
• Example: A Dog class inherits from an Animal class, indicating that Dog is a type of
Animal.

5. Dependency

• Definition: A weaker relationship where a change in one class may affect another class,
but the dependent class does not own the class it depends on.
• Notation: A dashed line with an arrow pointing from the dependent class to the class it
depends on.
• Example: A ShoppingCart class may depend on a Product class to calculate totals, but
it does not own the Product
In UML (Unified Modeling Language), interfaces play a crucial role in defining how
components interact. There are two main types of interfaces associated with components:
provided interfaces and required interfaces.

Provided Interface

Definition: A provided interface defines a set of operations that a component offers to other
components. It indicates what services or functionalities the component can provide.

• Representation:
o In UML component diagrams, a provided interface is represented as a lollipop
symbol (a small circle at the end of a line extending from the component).
• Purpose:
o To allow other components to use the services offered by the component.
o It defines a contract for how external entities can interact with the component.

Example: If a component PaymentProcessor has a provided interface called processPayment,


it signifies that other components can invoke this method to process payments.

Required Interface

Definition: A required interface defines a set of operations that a component needs from other
components to function properly. It indicates what services or functionalities the component
expects from its dependencies.

• Representation:
o In UML component diagrams, a required interface is represented as a socket
symbol (a small half-circle on the side of the component).
• Purpose:
o To indicate dependencies between components, showing what functionalities are
necessary for the component to operate.
o It establishes a contract for what services the component requires from other
components.

Example: If a component OrderManagement has a required interface called


fetchPaymentDetails, it signifies that it expects another component to provide this
functionality in order to retrieve payment information.
An abstract class is a class in object-oriented programming that cannot be instantiated directly.
Instead, it serves as a blueprint for other classes, providing a common interface and shared
behavior for subclasses. Abstract classes can contain both abstract methods (without
implementations) and concrete methods (with implementations).

Characteristics of an Abstract Class:

1. Cannot be Instantiated: You cannot create an object of an abstract class.


2. Abstract Methods: These methods are declared in the abstract class without
implementations, and subclasses must provide their own implementations.
3. Concrete Methods: Abstract classes can also include fully defined methods that can be
inherited by subclasses.
4. Inheritance: Subclasses that extend an abstract class must implement all its abstract
methods, ensuring specific functionality.

Representation in UML

In UML (Unified Modeling Language), an abstract class is represented with the following
conventions:

1. Class Name: The name of the abstract class is typically written in italics to indicate its
abstract nature.
2. Stereotype: You can optionally use the stereotype <<abstract>> above the class name
to explicitly indicate that it is an abstract class.
3. Attributes and Methods:
o Abstract methods are also shown in italics.
o Concrete methods (with implementations) are represented normally.

Example UML Representation

Here’s a textual representation of an abstract class named Vehicle with both abstract and
concrete methods:

typescript
Copy code
+-------------------------+
| <<abstract>> |
| Vehicle |
+-------------------------+
| - brand: String |
| - model: String |
+-------------------------+
| + start(): void | // Abstract method
| + stop(): void | // Abstract method
| + displayInfo(): void | // Concrete method
+-------------------------+

You might also like