• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hi Guies , How do you compare the extension VS modification

 
Lin Feng
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To me they are almost the same. If I use extension , I still can have chance to use modification some times later. vice versa.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you extension vs modification has sometimes the same results and sometimes it is different.
Just as a simple example to prove why you have to extend over modification is the situation where there are many apps using this class. If they are expecting a certain implementation, and in your new app that will use this class needs a different implementation, then modifying the class will break the older applications.
Example
I have a Commission class. App1 expects Commission to calculate as (Gross Profit-Costs)/10%, and this happens to be hard coded in the class. (Forget about some OOP ways around this bad design), Now App2 needs to calculate the commission as Gross Profit/5$.
In the Commission class the method calculated has this code. If you modify the class to have the new calculation then App1 will get the wrong results. However, if you extend the class and override the calculate method in the extended class with the new calculation then App1 can still use the Commission class, and App2 can use the NewCommision class without breaking each other.
Hope that helps in some part. There are other reasons in deciding when to do modify vs extend, but I have to get back to work.
Mark
 
Lin Feng
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark.
Why I have this question is because I do not think the extension and modify are enemy. On the other words, even I used modifying at this time, I still can use extension in the future to provide a total different solution. Just for the assignment, both of them should be fine.
Regards
Lin
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It can be used both. Meaning you could defend the choice to modify the Data class to change the deprecated parts, then extend to add lock(), unlock() and criteriaFind().
It is your choice completely, and you just defend your choice in the design.txt document.
Good Luck

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic