Question c object oriented analysis and design, Cheat Sheet of Computer Science

Object oriented analysis and design

Typology: Cheat Sheet

2024/2025

Uploaded on 05/21/2025

fred-loft
fred-loft 🇰🇪

1 document

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
a) Inheritance, Composition, and Aggregation in OOAD (6 Marks)
1. Inheritance
Definition: A mechanism where one class (child/subclass) derives properties and behavior from
another class (parent/superclass).
Example:
class Animal {
void eat() { System.out.println("This animal eats."); }
}
class Dog extends Animal {
void bark() { System.out.println("Dog barks."); }
}
Explanation: Dog inherits eat() from Animal.
2. Composition
Definition: A “has-a” relationship where one class contains an instance of another class. It
implies strong ownership; if the container is destroyed, so is the contained object.
Example:
class Engine {
void start() { System.out.println("Engine starts"); }
}
class Car {
private Engine engine = new Engine();
}
Explanation: Car has-a Engine. If Car is destroyed, so is the Engine.
3. Aggregation
Definition: A weaker “has-a” relationship compared to composition. The contained object can
exist independently of the container.
Example:
class Teacher {
String name;
}
class Department {
List<Teacher> teachers;
}
pf3
pf4

Partial preview of the text

Download Question c object oriented analysis and design and more Cheat Sheet Computer Science in PDF only on Docsity!

a) Inheritance, Composition, and Aggregation in OOAD (6 Marks)

  1. Inheritance Definition: A mechanism where one class (child/subclass) derives properties and behavior from another class (parent/superclass). Example: class Animal { void eat() { System.out.println("This animal eats."); } } class Dog extends Animal { void bark() { System.out.println("Dog barks."); } } Explanation: Dog inherits eat() from Animal.
  2. Composition Definition: A “has-a” relationship where one class contains an instance of another class. It implies strong ownership; if the container is destroyed, so is the contained object. Example: class Engine { void start() { System.out.println("Engine starts"); } } class Car { private Engine engine = new Engine(); } Explanation: Car has-a Engine. If Car is destroyed, so is the Engine.
  3. Aggregation Definition: A weaker “has-a” relationship compared to composition. The contained object can exist independently of the container. Example: class Teacher { String name; } class Department { List teachers; }

Explanation: Department aggregates Teachers. If a department is deleted, teachers still exist.

b) Coupling and Cohesion in Software Design (6 Marks)

  1. Coupling Definition: The degree of interdependence between software modules. Types: Tight (high) and Loose (low) coupling. Low Coupling: Modules can function independently. Promotes maintainability and reusability. High Coupling: Modules depend heavily on each other. Harder to change or test.
  2. Cohesion Definition: The degree to which elements within a module belong together. High Cohesion: A class/module does one thing well. Easier to understand and maintain. Low Cohesion: A class performs unrelated tasks. Hard to manage.
  3. Importance Striving for low coupling and high cohesion results in:
  • Easier debugging and testing.
  • Better code reuse and readability.
  • Improved scalability and flexibility. C) Model View Architecture

Views are usually built using HTML, CSS, and client-side scripts like JavaScript.

  1. Controller: The controller acts as the intermediary between the Model and the View. It handles user input, processes it (often using the Model), and returns the appropriate output (usually a View). For example, when a user clicks "submit," the controller captures that action, processes the data with the Model, and updates the View. Significance of MVC in Web Application Development: Separation of Concerns: Developers can work on the UI (View), business logic (Model), and user input (Controller) independently. Maintainability: Easier to update and maintain parts of the application without affecting others. Reusability: Components can be reused across different parts of the application or in future projects. Scalability: Clear structure makes it easier to scale up the application as it grows. Testability: Each component can be tested separately, making debugging and development more efficient.