AiPromptss
Back to browse

Design Pattern Implementation

Help refactor this code to use the Observer pattern : class UserService { updateUser ( userId , data ) { // Update user db . users . update ( userId , data ) ;…

Added May 19, 20260 views0 copies
Prompt
Help refactor
this
code to use the Observer pattern
:
class
UserService
{
updateUser
(
userId
,
data
)
{
// Update user
db
.
users
.
update
(
userId
,
data
)
;
// Send notifications
emailService
.
notify
(
userId
)
;
pushNotification
.
send
(
userId
)
;
analytics
.
track
(
userId
)
;
}
}
Goals
:
1.
Decouple notifications
2.
Make it extensible
3.
Improve testability
4.
Maintain single responsibility

Replace text in [BRACKETS] with your own values before pasting.