dimanche 14 novembre 2021

How to add attributes and behavior to an already written class

I wonder if there is a good practises to add some attributes and beahaviors to an already written class. In my example, I've made a basic class User. Now, in an other milestone, I want to add a notification system, and add a NotificationList in the class User (and the associated behaviors). In my opinion I have 3 choices :

  1. Write the new attributes/functions in my class User. But for each new feature, I will have to update a class that is already written, tested, etc. And the class User will be overloaded each time
  2. Use the inheritance : a class UserWithNotification that extends User, and make User abstract. But for each new feature in the future, I will have to extends, and extends, and extends...
  3. Use the decorator pattern, but in my case I'm not sure it fits

I'm trying to learn how a project can be as flexible as possible, to support new features that arrives late in the developpment. Thank's for help !

Aucun commentaire:

Enregistrer un commentaire