0% found this document useful (0 votes)
15 views1 page

Pattern

Uploaded by

ayahisham8888
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)
15 views1 page

Pattern

Uploaded by

ayahisham8888
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/ 1

The Decorator Design Pattern is a way to add new features to an object without changing its

structure or the original class. In this code, the UserManager class is improved with extra
functionality (logging) using this pattern.

How it works:

Core Class (UserManager)

 The UserManager class handles the main tasks like adding, editing, removing, and
fetching users from the database.
 It focuses only on these core functions and doesn't include any additional features.

Abstract Decorator (UserManagerDecorator)

 UserManagerDecorator is a base class that wraps around UserManager.


 It has the same methods as UserManager (like addUser, editUser, etc.), so it can replace
UserManager if needed.
 This decorator class contains a reference to the original UserManager object and can pass
method calls to it while also adding new functionality.

Concrete Decorator (LoggingUserManagerDecorator)

 This specific decorator, LoggingUserManagerDecorator, adds logging.


 For example:
o When you use addUser, it logs the username of the user being added and then
calls the original addUser method.
o Similarly, editUser logs the username of the user being edited and then lets the
original UserManager handle the editing.

You might also like