Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Abstract class with abstract class passed to constructor

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I can't believe I don't know the answer to this....but if I have a set of abstract classes like so:








 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i might be wrong but...
there is nothing wrong with the cast.
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any reason why you can't just change the parameter in the DogGroomer constructor to be a Dog object?
 
Edmund Castermund
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
k,
that's how I've been doing it, but I wasn't sure if it was considered bad design nor not. Under this scenario, the DogGroomer object will have both a Dog variable and a Pet variable and I wasn't sure if that was a problem or not. This is one of the (several) areas where I have ambiguity about little java 101 questions that bug me.
 
Edmund Castermund
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Matthew Brown wrote:Is there any reason why you can't just change the parameter in the DogGroomer constructor to be a Dog object?



that gives me a compile error... you have to have the constructor based on the superclass, and I was unclear as to how exactly that works and what the requirements are.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just thinking of this, which doesn't give a compiler error. The constructor doesn't have to relate to the superclass (though the super() call within it does).

However, I think your instincts are right - I definitely wouldn't have two variables for the same thing.

It's difficult to be sure, because I assume there's more to add to the class. But have you considered making the class generic?
 
Evildoers! Eat my justice! And this tiny ad's justice too!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic