0% found this document useful (0 votes)
8 views

GoF_Patterns

The document outlines five design patterns: Factory, Singleton, Strategy, Observer, and Adapter, each addressing specific problems in software development. The Factory Pattern abstracts object creation to reduce coupling, the Singleton Pattern ensures a single instance of a class, the Strategy Pattern allows interchangeable payment methods, the Observer Pattern facilitates notifications from instructors to students, and the Adapter Pattern integrates third-party APIs without altering existing systems. Each pattern is introduced or modified with specific classes and interfaces to enhance flexibility and maintainability.

Uploaded by

i233052
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

GoF_Patterns

The document outlines five design patterns: Factory, Singleton, Strategy, Observer, and Adapter, each addressing specific problems in software development. The Factory Pattern abstracts object creation to reduce coupling, the Singleton Pattern ensures a single instance of a class, the Strategy Pattern allows interchangeable payment methods, the Observer Pattern facilitates notifications from instructors to students, and the Adapter Pattern integrates third-party APIs without altering existing systems. Each pattern is introduced or modified with specific classes and interfaces to enhance flexibility and maintainability.

Uploaded by

i233052
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Factory Pattern

Category: Creational
Problem it Solves:
Creating instances like Course, Assessment, Certificate, or Subscription
may involve logic based on type or parameters. Using new directly in
client classes tightly couples the logic. Factory abstracts this creation.
Modified / Introduced:
Introduced:

 CourseFactory: A class that decides which type of Course to


create (e.g., standard, advanced, AI-integrated).

 AssessmentFactory: Creates objects like Quiz, Assignment,


Exam, etc.

 SubscriptionFactory: Returns a specific Subscription object


(Free, Monthly, Annual) based on parameters.

 ICourseFactory, IAssessmentFactory, ISubscriptionFactory:


Interfaces for the above factories to abstract creation logic.

Modified:

 Admin, Instructor, Student: Instead of using new Course() or


new Assessment(), they now use
CourseFactory.createCourse() etc., reducing direct coupling
with concrete classes.

2. Singleton Pattern

Category: Creational
Problem it Solves:
Classes like AIAssistant represent a system-wide utility/resource that
should have only one instance to avoid conflicts or redundancy.
Modified / Introduced:
Modified:

 AIAssistantSingleton: Implements Singleton by making


constructor private, and exposing a static getInstance()
method.

Introduced:

 Singleton pattern implementation: Static instance variable,


private constructor, and public static getInstance() method
added in each class.
.

3. Strategy Pattern

Category: Behavioral
Problem it Solves:
Different payment methods (e.g., credit card, PayPal, bank transfer) can
be implemented as interchangeable strategies in the Payment class,
making the class more flexible to extend and modify.
Modified / Introduced:
Introduced:

 IPaymentStrategy (Interface): Defines


processPayment(amount) method.

 CreditCardPaymentStrategy, PayPalPaymentStrategy,
BankTransferPaymentStrategy: Implement IPaymentStrategy
with specific logic.

Modified:

 Payment: Now includes a setStrategy(IPaymentStrategy*)


method and delegates processPayment() to the strategy
instance.

4. Observer Pattern

Category: Behavioral
Problem it Solves:
When Instructor posts an Announcement, all enrolled Students should be
notified. Observer decouples the instructor from student notification logic.
Modified / Introduced:
Introduced:

 IObserver (Interface): Has method update(message).

 ISubject (Interface): Has methods attach(IObserver*),


detach(IObserver*), notifyObservers().

 StudentObserver: Implements IObserver; each student acts


as a listener to announcements.

 AnnouncementPublisher: Implements ISubject, contains list


of observers (students), and notifies them on a new post.

Modified:
 Student: Implements IObserver interface.

 Instructor: Uses or delegates to AnnouncementPublisher to


notify enrolled students.

5. Adapter Pattern

Category: Structural
Problem it Solves:
If third-party APIs (e.g., external grading system or content delivery
platform) need to be integrated with Course or Grade, Adapter helps wrap
the incompatible interface without modifying existing system.
Modified / Introduced:
Introduced:

 ExternalGradingSystemAdapter: Implements your internal


grading interface IGradingSystem, internally calls the 3rd-
party API.

 ExternalContentAdapter: Wraps external content provider to


match internal expectations for the Course module.
Implements IContentProvider.

Modified:

 Course: Delegates content delivery via adapter instead of


directly using the 3rd-party API.

 Grade: Now calls the ExternalGradingSystemAdapter when


needed.

You might also like