This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About Data Class

 
G.T. Reddy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I modified the Data.java class to implement lock,unlock and criteriaFind methods.But they are asking to document reason for why you are modifing the Data class rather than extending.Could any one explain the difference between these approaches?.
thanks,
Reddy
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Reddy,
Did you really want an explanation of what the differences between modifying and extending are?
Modifying the Data class is when you change something in the class itself.
Extending the Data class is when you create a class that inherits from Data class. You then add your functionality in this new class, and only use the new class (not the original Data class) for the rest of your application.
Or did you want reasons for doing one instead of the other? If so, perhaps you could mention your reasoning first.
Regards, Andrew
[ October 13, 2003: Message edited by: Andrew Monkhouse ]
 
G.T. Reddy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
I know the meaning and implemented by modififing the Data.java class.But I am not able to explain the reason for doing one instead of the other.But one thing is if we extend Data class then one more class would me included unnecessarily in the project and we can prevent it by just modifing the Data class itself.SO no need to extend the Data class.
Am I correct?.Is there any thing else.If so please explain.
Thanks,
--Reddy.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi George, (or Tommy ?),
As you got an existing Data class, I suppose that you have an old assignment (in the new ones as mine, you are given only the interface).
In your case, I would modify Data instead of extending it because the given Data is not complete : as a Data class with no lock(),unlock() nor criteriaFind() method would be useless, it doesn't make much sense IMO to provide it as it is.
Best,
Phil.
[ October 13, 2003: Message edited by: Philippe Maquet ]
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Reddy,
Some things to think about before you start work on your assignment then ....
  • Are there any legacy applications which might break because of you changing / adding to the existing Data class? If so, you probably want to subclass rather than modify.
  • Is it possible that the original programmer may release a new version of the Data class? If so, then your modifications would have to be merged with theirs - it would be easier to subclass.
  • Do you want a clear distinction between the original programmer's code and your code? In which case having a subclass would give you that distinction.
  • Do the new methods really belong in the Data class? What is the responsibility of the Data class? Would a subclass be a better place for lock() and unlock()?
  • An alternate way of looking at the previous question: do you believe the supplied classes are "complete", in which case do you really want to modify a complete class?
  • Are there any methods where you might want to override existing functionality?
  • Can you possibly fix the deprecated code and/or javadoc comments without modifying the code?


  • You may very well look at some of the issues I mentioned and decide that they are silly and don't apply to the this assignment. But the reality is that they are all things you should be considering if you had the same choice in your real job. So you should already know the answers to these in order to make your decision on whether to modify or extend Data.
    Regards, Andrew
     
    Burk Hufnagel
    Ranch Hand
    Posts: 814
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Andrew,
    One option that Sun recommends(at least it's in a book - Effective Java - with Sun's logo on it) is favoring composition over inheritance. I know that I'd prefer to handle the locking issue using composition, but I'm concerned that the instructions (FBN assignment) specifically says:
    Part of your assignment will be to enhance the Data class. You may do this by modification or subclassing, but you should document the approach and reason for your choice.

    Given the instructions, I guess I'm stuck with modification or subclassing... grrr. Do you know of others who used composition and didn't get their score dinged for it?
    Thanks,
    Burk
     
    Lasse Koskela
    author
    Sheriff
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Burk Hufnagel:
    Given the instructions, I guess I'm stuck with modification or subclassing... grrr. Do you know of others who used composition and didn't get their score dinged for it?
    A lot of people have used a separate LockManager class. Search this forum for "LockManager" and you'll find plenty of discussion about the topic.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic