CSCI 370 - Lecture 3: The Problem with Inheritance and the Case for Composition


Overview

This lecture covered several key ideas in Software Engineering, particularly focusing on:


1. Does Adding More Team Members Speed Up Software Development?

Pros:

Cons:

Conclusion: Adding team members does not always speed up development; it depends on team composition, communication, and skills.


2. Requirements vs Specifications

Requirements:

Specifications:

Summary:


3. Problems with Inheritance in OOP

Inheritance:

Major Issues:

  1. Single Inheritance in Java:

    • Java allows only single inheritance.
    • You can’t inherit from multiple classes (e.g., can’t get both A.method1 and C.method1).
  2. Inheriting Unwanted Methods:

    • Subclasses inherit all methods and must override or remove unwanted ones.
    • Leads to code like empty method implementations (to disable behavior).
  3. Inheritance Chain Complexity:

    • Long chains (e.g., C -> D -> E) make it hard to understand what functionality is inherited.
    • Changing a parent class can break child classes, causing fragility.
  4. Tight Coupling:

    • Inheritance leads to strong coupling between parent and child.
    • A change in one class affects all descendants.

Real-World Consequences:

This is known as the Fragile Base Class Problem.


4. Composition Over Inheritance

Composition:

Benefits:

Principle:

Prefer Composition Over Inheritance

This is the 5th Object-Oriented Principle covered in the course.


5. Strategy Design Pattern

Purpose:

Problem Example:

Solution:

Key Idea:


Summary