• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Abstract Classes / Methods

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have a class AAA(abstract), with an abstract method method1().
Class BBB(abstract) extends AAA, but does not contain method1().
Classes CCC1,CCC2(both concrete) extends BBB, and implements method1().

This is shown here

This actually works, but as you can see method1() does not appear in BBB.
I guess the point is method1() is being implemented by in a subclass of AAA, its just not a direct subclass, but a sub-subclass.

Is this a bad thing to do, implementing behaviours for methods declared at the top of a hierachy, at the bottom?

Also, I think this only works because BBB is abstract, and if it were not, then it must implement method1().

Any thoughts? Thanks
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right about why it works.
I see nothing wrong with doing it, it's a matter of your model desing, you may have a case where such desing is the right thing.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider an exampleMost animals make a sound so it is reasonable to have the makeSound method declared in the Animal class. A mammal doesn't make a specific sound, so there is no need to override the makeSound method in the Mammal class. Dogs and pigs have specific sounds so you implement the makeSound method in those classes.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks good example, that clears it up well.
 
Everyone is a villain in someone else's story. Especially this devious tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic