Skip to content

Object Oriented Programming (OOP) Principles Including Encapsulation, Abstraction, Inheritance & Polymorphism Along with SOLID & Object Relationship Principles

Notifications You must be signed in to change notification settings

WillKirkmanM/oop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OOP

Object Oriented Programming (OOP) Principles Including Encapsulation, Abstraction, Inheritance & Polymorphism Along with SOLID & Object Relationship Principles

Core Principles

  • Encapsulation

    • Bundle data and methods; control access using public, private, and protected.
    • Use getters/setters to validate or control access.
  • Abstraction

    • Expose essential behavior via interface or abstract class.
    • Hide implementation details so callers rely on stable contracts.
  • Inheritance

    • Reuse and extend behavior with extends and super.
    • Model "is-a" relationships.
  • Polymorphism

    • Subclasses override methods; code works with base types or interfaces.

Object Relationships

  • Association: objects use each other.
  • Aggregation: a has-a relationship; parts can exist independently.
  • Composition: strong ownership; parts' lifecycle tied to the parent.

SOLID Principles

  • SRP: One responsibility per class.
  • OCP: Open for extension, closed for modification.
  • LSP: Subtypes must be substitutable for their base types.
  • ISP: Prefer many small, focused interfaces.
  • DIP: Depend on abstractions, not concrete implementations.

Minimal TypeScript examples

// interface
interface Shape { area(): number; }

// abstract class
abstract class Animal {
  protected name: string;
  constructor(name: string) { this.name = name; }
  abstract makeSound(): void;
}

// inheritance & polymorphism
class Dog extends Animal {
  makeSound() { console.log('Woof'); }
}

// encapsulation
class BankAccount {
  private balance = 0;
  deposit(amount: number) { if (amount > 0) this.balance += amount; }
  getBalance() { return this.balance; }
}

About

Object Oriented Programming (OOP) Principles Including Encapsulation, Abstraction, Inheritance & Polymorphism Along with SOLID & Object Relationship Principles

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published