📘 Class Diagrams (OOAD – UML)
🔹 1. Definition
A Class Diagram is a static UML diagram that shows the structure of a system by representing:
- Classes
- Attributes
- Methods (operations)
- Relationships between classes
👉 Simple idea:
It tells us what the system is made of and how parts are connected, not how they behave over time.
🔹 2. Purpose of Class Diagrams
- Describe system structure
- Show relationships between objects
- Help in database and software design
- Act as a blueprint for coding
- Improve system understanding
🔹 3. Basic Structure of a Class ⭐
A class is shown as a 3-part box:
----------------------
| Class Name |
----------------------
| Attributes |
----------------------
| Methods |
----------------------
🔹 4. Components of Class Diagram
🔸 4.1 Class Name
- Top section of the box
- Represents entity (e.g., Student, Book)
🔸 4.2 Attributes
- Data members (variables)
- Represent properties
Example:
🔸 4.3 Methods (Operations)
Example:
🔹 5. Relationships in Class Diagrams ⭐
🔸 5.1 Association
A general relationship between two classes.
Example:
Teacher —— Student
👉 A teacher teaches students
🔸 5.2 Multiplicity
Defines how many objects participate.
| Symbol |
Meaning |
| 1 |
One |
| 0..1 |
Zero or one |
| * |
Many |
| 1..* |
One or many |
🔸 5.3 Aggregation (Weak Has-A)
- Whole-part relationship
- Part can exist independently
Example:
Department ◇—— Teacher
🔸 5.4 Composition (Strong Has-A)
- Strong ownership
- Part cannot exist without whole
Example:
House ◆—— Room
🔸 5.5 Inheritance (Generalization)
- One class inherits another
Example:
Animal
↑
Dog
🔸 5.6 Dependency
- Temporary relationship
- One class uses another
🔹 6. Example (Library System)
🔹 Classes:
🔹 Class Diagram Representation:
Book
- title
- author
+ issue()
Member
- name
- id
+ borrowBook()
Relationship:
Member —— borrows —— Book
🔹 7. Types of Class Diagrams
🔸 7.1 Conceptual Class Diagram
- High-level view
- Used in analysis phase
🔸 7.2 Specification Class Diagram
- More detailed
- Used in design phase
🔸 7.3 Implementation Class Diagram
- Close to actual code
- Used in coding phase
🔹 8. Steps to Create Class Diagram
🔹 Step 1: Identify Classes
- Find nouns in problem statement
🔹 Step 2: Define Attributes
🔹 Step 3: Define Methods
🔹 Step 4: Define Relationships
- Association, inheritance, etc.
🔹 Step 5: Add Multiplicity
- Define quantity relationships
🔹 9. Advantages of Class Diagrams
- Clear system structure
- Easy to convert into code
- Improves communication
- Helps database design
- Supports reuse
🔹 10. Important Rules / Guidelines
- Keep classes simple and meaningful
- Avoid too many attributes/methods
- Maintain high cohesion & low coupling
- Use proper relationships
- Follow UML notation
🔹 11. Likely Exam Questions
- Define class diagram.
- Explain components of a class diagram.
- What is association?
- Difference between aggregation and composition.
- Explain inheritance in class diagrams.
- What is multiplicity?
- Draw class diagram for library system.
- Types of class diagrams.
- Steps to create class diagram.
- Advantages of class diagrams.
🔹 12. Quick Revision Summary 🧠
Key Relationships:
- Association
- Aggregation
- Composition
- Inheritance
👉 Trick to Remember:
"CARM-I"
(C → Class, A → Attributes, R → Relationships, M → Methods, I → Inheritance)