Object-Oriented Programming Concepts

  1. Encapsulation • Purpose: • Encapsulation bundles data with methods that operate on that data, restricting direct access to some of an object’s components. • Usage in Codebase: • Data Hiding and Access Control: • Classes: LiveShow, ShowSlot, User, Booking • Fields are declared private to prevent unauthorized access. • Public getter and setter methods provide controlled access to the fields. • Protects the integrity of the data by preventing external entities from putting the objects into invalid states.
  2. Polymorphism • Purpose: • Polymorphism allows objects of different classes to be treated as objects of a common superclass, enabling one interface to be used for a general class of actions. • Usage in Codebase: • Ranking Strategy Interface: • Interface: RankingStrategy • Implementations: StartTimeRankingStrategy, potential future strategies • The system interacts with RankingStrategy types, allowing different implementations to be used interchangeably. • Enables the LiveShowService to utilize any concrete implementation of RankingStrategy without changing its code.
  3. Abstraction • Purpose: • Abstraction focuses on essential qualities rather than specific characteristics, hiding complex implementation details. • Usage in Codebase: • Service Interfaces and Abstract Classes: • Interfaces: RankingStrategy • Defines abstract methods without implementation details. • Service Classes: LiveShowService, BookingService • Provide high-level methods for operations like booking tickets, without exposing the underlying data structures. • Result: Simplifies interaction with complex systems by providing simple interfaces.
  4. Inheritance • Purpose: • Inheritance allows a new class to inherit properties and methods from an existing class, promoting code reuse. • Usage in Codebase: • Exception Hierarchy: • Classes: Custom exceptions like BookingException inherit from Exception. • Provides a structured way to handle different error types. • Note: The codebase primarily favors composition over inheritance, focusing on interfaces and implementations rather than class hierarchies.
  5. Composition • Purpose: • Composition models a has-a relationship, where objects are composed of other objects, promoting code reuse and flexibility. • Usage in Codebase: • Object Relationships: • Class LiveShow has a list of ShowSlot objects. • Class ShowSlot contains booking information and waitlists. • Result: Complex behaviors are built by combining simpler objects, enhancing modularity.