CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2011

    To use Classes that extend a base class or not

    I am wondering what is the best practise for doing the following;

    I am going to query an api, and it will return xml similiar to this.

    <Event Type=A>

    <Event Type=B>

    <Event Type=C>



    I'll then use this to build an arraylist of objects. Should I;

    1) Create a class with all the above fields in the 1 class of type Event, or
    2) Create an Event base class with id as it's only field then 3 more classes like 'EventTypeC' that extends Event and then add the C_Specific value in this constructor?

    If it's number 2, what would be the best way of taking this information then building an ArrayList<With_Multiple_Object_Types>?

    Thanks in advance for the feedback. I'm assuming people will say it's a personal choice but I guess I'm looking for what is the best approach. I'm learning so would like to learn the right way, but i'm weighing up the extra effort of deciding what object i'm dealing with etc when i decide to scan the arraylist and deal with each event independantly and perform actions based on the event type.

    Thanks again


  2. #2
    Join Date
    May 2006

    Re: To use Classes that extend a base class or not

    If you have values that are specific to one type and are meaningless to another type then go with approach 2. Or if the behaviour of the types is different so for example you will need different method implementations for each type then again use approach 2.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.