Results 1 to 7 of 7
  1. #1
    keo
    keo is offline Member
    Join Date
    May 2010
    Posts
    34
    Rep Power
    0

    Default Superclass question

    I am refactoring a few classes to form a superclass.

    If I have a method header that appears in all my sub classes, but contain different bodys and parameters in it, how do i check which class requested it? Or would I just leave the method in its own class?
    Thanks

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Why would you need to "check which class requested it"?

    In any case, if the signatures are not the same (and they are not when there are different arguments) then it does not belong in some abstract "super" class.

  3. #3
    keo
    keo is offline Member
    Join Date
    May 2010
    Posts
    34
    Rep Power
    0

    Default

    The method signatures are the same, but the bodys are different, and will cause action to variables belonging uniquely to each class.

  4. #4
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    348
    Rep Power
    4

    Default

    Keo,

    You could just leave them as is, but I would place an abstract method in the super class to ensure consistancy. This does mean that ALL sub-classes must override the method, but it does make calling the method from an array of different sub-classes easier.

    Regards.

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by Ronin View Post
    but I would place an abstract method in the super class to ensure consistancy
    Which you can't do if they have different parameters, as stated in the OP. Unless of course you want to do an Object varargs which completely defeats the purpose and would no longer ensure "consistency" in any way, shape, or form.

  6. #6
    keo
    keo is offline Member
    Join Date
    May 2010
    Posts
    34
    Rep Power
    0

    Default

    Okay, Thank you everyone!

  7. #7
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    348
    Rep Power
    4

    Default

    Quote Originally Posted by masijade View Post
    Which you can't do if they have different parameters, as stated in the OP.

    You are quite right, but given the OP's second post which stated that the signatures where the same, I assumed they confused the term parameters with variables.

    Regards.

Similar Threads

  1. Class and SuperClass
    By pompeez in forum New To Java
    Replies: 2
    Last Post: 08-05-2009, 10:55 AM
  2. superclass and subclass
    By mr idiot in forum New To Java
    Replies: 19
    Last Post: 01-03-2009, 07:29 AM
  3. SuperClass of an Object
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-06-2007, 02:51 PM
  4. Replies: 0
    Last Post: 11-12-2007, 11:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •