Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: class hierarchy

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default class hierarchy

    Hello all...
    I am writing a class hierarchy for an assignment in my high school Java class and have a quick question on the structure...

    I need to make book, novel, magazine, technical journal and textbook classes / interfaces. Should book be an interface or an abstract class?
    I couldn't think of anything to put in the constructor so i made it an interface...do you see any problems with just an interface and they all implement it?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,243
    My Mood
    Hungover
    Thanks
    142
    Thanked 617 Times in 528 Posts

    Default Re: class hierarchy

    It really depends. If you can justify it, then go with your justification. But it seems strange to me for every class to implement Book. By that logic, a magazine or a journal are books?

    I could also see things like passing an author, title, number of pages, etc into a Book constructor.

    But whether or not the constructor takes arguments does not determine whether a class is an abstract class or an interface (or a plain old class). An interface defines a common contract that any implementing classes agree to, an abstract class defines a subset of functionality that extending classes agree to complete.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Feb 2012
    Posts
    58
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: class hierarchy

    I think the abstraction should be highest from the root of the hierarchical tree, then decreased downward from the tree.

Similar Threads

  1. Replies: 7
    Last Post: July 21st, 2011, 02:29 PM
  2. Class hierarchy... giving me a headache, so I could use some help
    By Kerr in forum Object Oriented Programming
    Replies: 6
    Last Post: May 30th, 2011, 05:03 PM
  3. Replies: 3
    Last Post: April 13th, 2011, 03:30 PM
  4. Help requested - testing a class with a tester class, no methods allowed.
    By miketeezie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 21st, 2011, 09:40 PM
  5. Replies: 0
    Last Post: April 11th, 2010, 08:56 AM

Tags for this Thread