API Design Question

Discussion in 'Java' started by Scott, Jul 12, 2003.

  1. Scott

    Scott Guest

    Hi,

    I'm designing an API of container objects such that:

    there is an abstract ContainerObject,

    ContainerObjectA extends ContainerObject, and stores:
    ContainerObjectB, which extends ContainerObject, and stores:
    ContainerObjectC, which extends ContainerObject, and stores:
    ContainerObjectD, which also extends ContainerObject.

    However, I wish to make ContainerObjectD an abstract class that must be
    extended by the API user to allow for customization of the final level of
    containment. This may seem a little odd, but the data is organized in
    such a way that the upper levels of containment objects will be identical,
    but the lower objects will differ (i.e. ContainerObjectD will contain
    one or more customizable objects). So, my question is, how do I handle
    ContainerObjectC? - it will only ever access the interfaces in
    ContainerObjectD defined by the abstract ContainerObject, not any of the
    extended elements. But, I won't know what the name or location of the
    extended object of ContainerObjectD will be. Do I just leave it to the
    API user to edit ContainerObjectC and insert the name of the new extended
    class, or is there a way to approach this is a more structured manner?
    Also, can an abstract class be extended by an abstract class? Should I
    use an interface instead? That will still leave the problem of how I
    should refer to the abstract class within a non-abstract one. I hope this
    makes sense, and thanks for any advice!

    Best Regards,

    Scott
    Scott, Jul 12, 2003
    #1
    1. Advertising

  2. Scott

    rkm Guest

    You lost me when you said ContainerObjectC needs to know
    about the new extended class. I thought only
    ContainerObjectD needed to know about that.
    Rick
    rkm, Jul 12, 2003
    #2
    1. Advertising

  3. Scott

    Scott Guest

    On Sat, 12 Jul 2003 16:11:24 -0600, rkm <> wrote:

    >You lost me when you said ContainerObjectC needs to know
    >about the new extended class. I thought only
    >ContainerObjectD needed to know about that.
    >Rick


    Thanks for the reply.

    Actually, ContainerObjectD is abstract, so the new extended object
    will essentially replace ContainerObjectD, and will be the object that
    ContainerObjectC contains (!) So, ContainerObjectC will have to have
    knowledge of the extended class.

    Scott
    Scott, Jul 13, 2003
    #3
  4. Scott

    xarax Guest

    Scott <> wrote in message news:<>...
    > On Sat, 12 Jul 2003 16:11:24 -0600, rkm <> wrote:
    >
    > >You lost me when you said ContainerObjectC needs to know
    > >about the new extended class. I thought only
    > >ContainerObjectD needed to know about that.
    > >Rick

    >
    > Thanks for the reply.
    >
    > Actually, ContainerObjectD is abstract, so the new extended object
    > will essentially replace ContainerObjectD, and will be the object that
    > ContainerObjectC contains (!) So, ContainerObjectC will have to have
    > knowledge of the extended class.
    >
    > Scott


    No, it just needs knowledge of the ContainerObjectD class/interface.
    The concrete implementation can be anything that extends the class
    or implements the interface that you specify as ContainerObjectD.

    An interface is probably better than an abstract class in this
    case.
    xarax, Jul 13, 2003
    #4
  5. Scott

    Scott Guest

    On Sun, 13 Jul 2003 14:57:42 -0700, Lee Fesperman
    <> wrote:

    >Basic answers first:
    >
    >+ An abstract class can extend an abstract class (or a non-abstract class).
    >
    >+ You don't reveal enough of what you are doing to tell if you should use an interface,
    >but it is likely.
    >


    Thanks for the reply. I've been doing a bit of research and
    re-thinking, and I'm going to do the whole thing over again with an
    interface. It does seem to be the best route. Thanks again!

    Scott
    Scott, Jul 14, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. andrew queisser

    API design question

    andrew queisser, Feb 21, 2006, in forum: C Programming
    Replies:
    2
    Views:
    334
    Walter Roberson
    Feb 22, 2006
  2. Marcel Müller
    Replies:
    4
    Views:
    1,003
    Öö Tiib
    Jan 1, 2011
  3. Adam Skutt
    Replies:
    1
    Views:
    506
    Marcel Müller
    Jan 1, 2011
  4. Adam Skutt
    Replies:
    2
    Views:
    700
    Adam Skutt
    Jan 1, 2011
  5. Ethan Furman

    API design question for dbf.py

    Ethan Furman, Jul 6, 2012, in forum: Python
    Replies:
    0
    Views:
    155
    Ethan Furman
    Jul 6, 2012
Loading...

Share This Page