AI Instructor Live Labs Included

Object-Oriented Design in Java

Learn OOP design patterns and SOLID principles in Java by building a RideShare simulation. Covers Factory, Builder, Strategy, Observer, Decorator, Adapter, and Dependency Injection through hands-on refactoring.

Intermediate
17h 25m
14 Lessons
SMU-JAVA-OOP
Java OOP Design Patterns Badge

View badge details

About This Course

Master object-oriented design principles and patterns in Java by building a RideShare simulation from the ground up. This course covers SOLID principles, Factory, Builder, Strategy, Observer, Decorator, Adapter, and Dependency Injection patterns through hands-on refactoring exercises. Students progressively transform a monolithic codebase into a clean, extensible, pattern-driven application.

Course Curriculum

14 Lessons
01
AI Lesson
AI Lesson

SOLID Principles

1h 0m

Learn all five SOLID principles with real Java examples from the FleetFlow ride-sharing domain. Covers Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion Principle with before/after code comparisons.

02
Lab Exercise
Lab Exercise

SOLID - Lab Exercises

1h 30m 3 Exercises

Hands-on exercises refactoring a monolithic RideShareApp to apply SOLID principles. Students extract domain classes (SRP), split the Vehicle interface into focused role interfaces (ISP), and wire a MapService abstraction into TripDispatcher (DIP).

Apply SRP — Extract Domain Classes Extract Vehicle, Driver, Rider, and Trip domain classes from the monolithic RideShareApp. Each stub class exists with TODO markers — implement their fields, constructors, and getters. ~15 min
Apply ISP — Split the Vehicle Interface Open Driveable.java and Trackable.java stubs, declare the appropriate methods on each, and update Vehicle.java to implement both interfaces. Neither interface should force unneeded methods. ~15 min
Apply DIP — Depend on MapService Interface Declare the MapService interface, implement SimpleMapService, and update TripDispatcher to accept MapService via constructor injection. Wire it in RideShareApp.main() — TripDispatcher must never instantiate a concrete map service itself. ~15 min
03
AI Lesson
AI Lesson

Factory and Builder Patterns

1h 0m

Learn the Factory and Builder creational patterns. Factory centralizes object creation behind a single method so callers never use new directly. Builder assembles complex objects with fluent setter chains. Both patterns are applied to the RideShare vehicle and trip creation scenarios.

04
Lab Exercise
Lab Exercise

Factory & Builder - Lab Exercises

1h 30m 3 Exercises

Hands-on exercises implementing VehicleFactory with an arrow switch, building a fluent TripBuilder with validation, and adding a config-file vehicle loader. Students replace all direct new Car/Van/Motorcycle calls with factory calls.

Implement VehicleFactory Implement createVehicle(String type, String id, String make) in VehicleFactory using an arrow switch. Throw IllegalArgumentException for unknown types. Replace all direct new Car/Van/Motorcycle calls in Main.java with factory calls. ~15 min
Implement TripBuilder Implement fluent setter methods in TripBuilder for driver, rider, vehicle, and pricingStrategy (each returns this). Implement build() with null validation. Replace the direct Trip constructor call in TripDispatcher with the fluent builder chain. ~15 min
Add Vehicle Config Loader to Factory Add loadVehicleFromConfig(Map<String, String> config) to VehicleFactory that reads type, id, make keys and delegates to createVehicle(). Test it in Main.java and verify the factory throws clearly when type is missing from the config map. ~15 min
05
AI Lesson
AI Lesson

Strategy Pattern

1h 0m

Learn the Strategy Pattern — defining a family of interchangeable algorithms encapsulated behind a common interface. Applied to RideShare pricing: StandardPricing, SurgePricing, and FlatRatePricing can be swapped at runtime without changing TripDispatcher. Also covers Strategy vs Template Method.

06
Lab Exercise
Lab Exercise

Strategy - Lab Exercises

1h 30m 3 Exercises

Hands-on exercises implementing StandardPricing, SurgePricing, and FlatRatePricing strategies, injecting a strategy into TripDispatcher via constructor, adding a null-guarded setter, and building an interactive pricing menu that swaps the active strategy at runtime.

Implement the Three Pricing Strategies Create StandardPricing, SurgePricing, and FlatRatePricing implementing PricingStrategy. StandardPricing: $2/km minimum $5. SurgePricing: constructor accepts multiplier, fare = base × max(1.0, riderDriverRatio × multiplier). FlatRatePricing: always returns the flat fee. ~15 min
Inject Strategy into TripDispatcher Add a PricingStrategy field and constructor to TripDispatcher. Add a null-guarded setPricingStrategy() setter. Replace the hardcoded fare method with a delegation call to pricingStrategy.calculateFare(). Verify standard fare and surge fare compute correctly. ~15 min
Runtime Strategy Swap Menu In Main.java, instantiate TripDispatcher with StandardPricing. Add a console menu option "Change pricing: 1) Standard 2) Surge 3) Flat Rate" that swaps the strategy. Print the current strategy name and computed fare for a sample 12km trip after each swap. ~15 min
07
AI Lesson
AI Lesson

Observer Pattern

1h 0m

Learn the Observer Pattern — one-to-many dependency where subject notifies all observers on state change. Applied to Trip completion: ReceiptService, DriverEarningsService, and AnalyticsService are observers registered on Trip. Covers thread safety with CopyOnWriteArrayList and memory leak prevention.

08
Lab Exercise
Lab Exercise

Observer - Lab Exercises

1h 30m 3 Exercises

Hands-on exercises implementing ReceiptService, DriverEarningsService, and AnalyticsService observers, making Trip observable with add/remove/notify methods, registering all observers in Main.java, and adding a StatusLogObserver to verify notification order.

Implement the Three Observer Services Open ReceiptService, DriverEarningsService, and AnalyticsService stubs. Implement onTripCompleted(Trip trip) on each: ReceiptService prints rider name and fare, DriverEarningsService prints driver name and 80% cut, AnalyticsService increments tripCount and prints total. ~15 min
Make Trip Observable Open Trip.java. Add a List<TripObserver> observers field. Implement addObserver() and removeObserver() methods. Update complete() to iterate the observer list and call onTripCompleted(this) on each, wrapping each call in try-catch so one failing observer does not block the rest. ~15 min
Register Observers and Test End-to-End In Main.java, after creating a Trip, register all three observers. Simulate a completed trip and verify all three services print their output. Add a StatusLogObserver that prints "Trip COMPLETED: [tripId]" and confirm notification order matches registration order. ~15 min
09
AI Lesson
AI Lesson

Decorator and Adapter Patterns

1h 0m

Learn the Decorator Pattern (adding behavior at runtime without subclassing) and the Adapter Pattern (making incompatible interfaces work together). Decorator is applied to TripService add-ons; Adapter wraps LegacyGpsLibrary behind the MapService interface.

10
Lab Exercise
Lab Exercise

Decorator & Adapter - Lab Exercises

1h 45m 3 Exercises

Hands-on practice applying the Decorator and Adapter patterns to the RideShare simulation. Extend trip pricing with stacked decorators and integrate a legacy GPS system through an adapter.

Implement the Decorator Pattern for Trip Pricing Build a decorator chain for TripService that adds cancellation insurance and premium support fees on top of a base trip price. ~20 min
Stack Multiple Decorators Wrap a BasicTrip with both CancellationInsuranceDecorator and PremiumSupportDecorator and verify that the final price correctly sums all layers. ~20 min
Adapt a Legacy GPS Library Implement LegacyMapAdapter to make the incompatible LegacyGpsLibrary work with the MapService interface used by the RideShare routing system. ~20 min
11
AI Lesson
AI Lesson

Dependency Injection

30m

Learn how to implement Dependency Injection manually in Java by building a simple DI container, applying constructor injection throughout the RideShare app, and establishing a clean composition root using the AppContainer pattern.

12
Lab Exercise
Lab Exercise

Dependency Injection - Lab Exercises

1h 45m 3 Exercises

Hands-on practice refactoring the RideShare simulation to use constructor injection throughout and wiring the entire object graph in a single AppContainer composition root.

Refactor to Constructor Injection Remove all direct instantiation from service classes and replace with constructor-injected interfaces. ~20 min
Build the AppContainer Composition Root Create AppContainer to wire the entire RideShare object graph in one place, assembling services bottom-up using constructor injection. ~20 min
Verify Isolation with a TestAppContainer Create a TestAppContainer that wires mock implementations and confirm that TripBookingService works without real payment or notification services. ~20 min
13
AI Lesson
AI Lesson

Capstone Briefing

20m

A comprehensive review of all six design patterns covered in the course and a detailed briefing on the RideShare capstone project requirements that students will implement in the final lesson.

14
Lab Exercise
Lab Exercise

Capstone Project

2h 5m 3 Exercises

The final capstone project for Object-Oriented Design in Java. Students implement a complete RidePool feature that integrates all six design patterns: Factory, Builder, Strategy, Observer, Decorator, and Adapter — assembled with Dependency Injection in a composition root.

Implement RidePool with the Builder Pattern Build the RidePool class using the Builder pattern, integrating VehicleFactory for vehicle creation and configuring passenger capacity. ~25 min
Implement RidePoolPricingStrategy and Observer Events Build the RidePoolPricingStrategy using the Strategy pattern and implement the PassengerJoinedEvent observer chain with PoolPriceRecalculator and PoolCapacityChecker. ~30 min
Wire the Full System with RidePoolContainer Implement RidePoolAdapter to bridge RidePool with the legacy dispatch system, then build RidePoolContainer as the composition root that wires all components together. ~25 min

This course includes:

  • 24/7 AI Instructor Support
  • Live Lab Environments
  • 7 Hands-on Lessons
  • 6 Months Access
  • Completion Badge
  • Certificate of Completion
Java OOP Design Patterns Badge

Earn Your Badge

Complete all lessons to unlock the Java OOP Design Patterns achievement badge.

Category
Skill Level Intermediate
Total Duration 17h 25m
Java OOP Design Patterns Badge
Achievement Badge

Java OOP Design Patterns

Awarded for completing the Java OOP Design Patterns course, demonstrating mastery of creational, structural, and behavioral design patterns in Java.

Course Object-Oriented Design in Java
Criteria Complete all lessons and pass assessments in the Java OOP Design Patterns course.
Valid For 730 days

Skills You'll Earn

Design Patterns SOLID Principles Creational Patterns Structural Patterns Behavioral Patterns Refactoring

Complete all lessons in this course to earn this badge