π 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)