Use enum or subclassing to differentiate between different elements?

Hello all,
I have a design decision to make.
I have two different Elements with everything the same except the name.
So I have two ideas on how this can be solved.
1. Through subclassing.
2. Through enumeration.
I have tried to make two examples of this so you can recommend 1 or 2 only on a conceptual level not implementation.
Sub classing
public class Element {
     //Methods     
public class A extends Element {
     //Nothing
public class B extends Element {
     //Nothing
public class Main {
     public static void main(String[] args) {
          Element elm = new A();
          if (elm instanceof A){}
          else if (elm instanceof B){}
}Enumeration
public class Element {
     public enum Type {A, B}
     private Type type;
     public Element(Type type) {
          this.type = type;
     public Type getType() {
          return type;
     //Methods
public class Main {
     public static void main(String[] args) {
          Element elm = new Element(Type.A);
          switch(elm.getType()) {
               case A:
               case B:
}Thanks /Farmor
Edited by: Farmor on Dec 15, 2009 3:14 PM (Spelling error)

Thanks for the answers.
Then I will go with the enum solution that will give me a lot of free things.
Such as I can limit the API user to only choose between my predefined values and the use of my API will be much easier when used in a good IDE.
/Farmor

Similar Messages

  • Sharing songs between different iTunes accounts on the same Mac

    Hello
    I am a newbie to Mac. My wife and I both have seperate iTunes accounts set up on our seperate user accounts on our MacBook. Can we share songs between our accounts?

    *BA Mack* wrote:
    Can we share songs between our accounts?
    Zevoneer wrote:
    You might find this article useful: iTunes: How to share music between different accounts on a single computer
    The process for sharing libraries is much [easier in iTunes 8|http://forums.macworld.com/thread/105366?tstart=0]. If you simply want to share a few songs, you are better off having a copy of those tracks in each of your libraries, but there is little point to that as you can access each other’s libraries in read-only fashion.

  • Why do I have to use the tab key even more to tab between page elements.

    Firefox versions prior to ver 4 I used the tab key to tab between page elements (form elements, buttons, etc). I upgraded to ver 4 and now when I tab from form element to form element I first see a gray line outlining the element area and then another press of the tab the element becomes active for me to use. I now have to use double the tab keys to move between form elements.

    Hello new_mac_user, see if the next works
    # In the [[Location bar autocomplete|Location bar]], type '''about:config''' and press '''Enter'''. The about:config "''This might void your warranty!''" warning page may appear.
    # Click '''I'll be careful, I promise!''', to continue to the about:config page.
    # in search field type (or copy/paste from here) '''accessibility.tabfocus'''
    # double-click on it and change the value to '''4''' (probably you have 1 the default on mac)
    # click ok, exit firefox and restart it.
    with the above you give focus to links (and linked images) only when you press the tab key.
    see for more info : http://kb.mozillazine.org/Accessibility.tabfocus
    https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/Preference_reference/accessibility.tabfocus
    thank you

  • Use ccBPM mainly for correlation between different systems

    In his presentation: "Design Patterns for SAP NetWeaver Exchange Infrastructure"
    William Li ,from SAP NetWeaverRIG Americas, stats that following:
    *Use ccBPM mainly for correlation processing between messages from different systems
    Although this practice is well known Ito me , would like to know what stands behind this recommendation (Except for
    eSOA BP). is it performance issue, other...
    your insights will be most wellcome.

    Nimrod Gisis wrote:Hi Nimrod,
    ccBPM offers achieving some difficult requirements easily , that means some cases using standard way of integration not possible .it is true that ccBPM scenarios uses one more layer(BPE engine) but it doesn't mean that it is going to give worst performance.
    i had done couple of implementations where we used extensively ccBPM to achive complex integration logics, i never felt ccBPM performance point of view any problems, all interfaces working perfectly in production.my view is it is really awesome.
    we have to design any interfaces by following best architectural standards in case of ccBPM also same,there is so much negative publicity about ccBPM, but is it not all true.
    the thing that intrigues me the most is the reference to different systems .
    > if lets say I have to construct a mesage from 20 other messages taken from the same applicative system....
    > will that be a "good practice" or an architectural design flop?
    >
    it is a good practise to use ccBPM in this case and it is offering correlation mechanism to maintain the reaction between messages so that you can easily differentiate and suppress the unwanted messages.
    Regards,
    Raj

  • HT1203 iTunes: How to share music between different accounts on a single computer - I tried to use the instructions to configure 2 different windows users sharing the same iTunes library.  I could not get this to work per the instructions.

    I tried to configure 2 windows users accounts using a single library per the instructions in HT1203.  My iTunes library is on an external drive.  I cannot get this to work.  Any suggestions?

    To give other users read-only access to your iTunes library, use the Sharing features of iTunes. Sharing works over the local network as well as on the same computer. See the built-in help for details.
    If you want to give full read/write access to more than one user, see the support article linked below.
    iTunes: How to share music between different accounts on a single computer
    There is a way to share the library without moving it to a secondary volume. If you really need to do that, ask for instructions.

  • How can I use DOM to copy Nodes between different XML Document ?

    Can I copy one Node or Element from one XML Document to another Document by DOM ?
    Because I use the Xerces , but it is not work if I want to copy Node between different Document, or I am doing something wrong. Anyone can help me , I will deeply appreciated !!

    check out the importNode() method of Document.

  • Using XML to exchange data between different databases?

    Hi,
    Does anyone know of any case-studies or tutorial's where XML has been used to transfer data between different databases... i.e. oracle to sql server?
    I basically looking into the differences between two schema's and what sort of tranformations need to take place.
    Thanks in advance guys!

    Hi,
    Does anyone know of any case-studies or tutorial's where XML has been used to transfer data between different databases... i.e. oracle to sql server?
    I basically looking into the differences between two schema's and what sort of tranformations need to take place.
    Thanks in advance guys!

  • Is there any way to stop the delay between different sets of speakers when using airport express?

    Is there any way to stop the delay between different sets of speakers when using airport express?

    Unfortunately, I don't have either a Slingbox or iHome speakers so I won't be able to reproduce any of the issues you are having. With the fact that you live in large apartment complex would still lead me to believe that Wi-Fi interference may be the reason that you are having streaming issues.
    I suggest you perform a simple site survey, using utilities like iStumbler, or AirRadar to determine potential areas of interference, and then, try to either eliminate or significantly reduce them where possible.

  • How can I sync/import/export bookmarks between different users on the same computer and both using the Firefox browser?

    All help instructions are for importing or exporting bookmarks/favourites between different brands of browsers.

    Many thanks twalker for your prompt and simplified explanation for resolving my problem which is much appreciated by this tarnished silver surfer. I will now arrange to download FX4 and follow your instructions.

  • My daughter and I both have an iPhone and we have shared my apple ID. Now her phone is syncing with mine and we want to have different contacts. How do I differentiate between the two phones?

    My daugher and I both have an iPhone and we have shared my apple ID. She just replaced her phone and now our contacts are syncing -- and we don't want that. How do I differentiate between the two phones?

    Is the same Apple iCloud account being accessed on each iPhone?

  • HT3819 How to use homesharing between different user accounts on the same iMac?

    I find plenty of articles about homesharing on iTunes between computers, but not between two different user accounts on the same iMac.  Any advice or direction to an existing artical is greatly appreciated.  I'm knew to the Mac and still have Windows on the brain.
    I am trying to share iTunes music and movie purchases between my user login and my wife's.
    Thanks

    Hello careymp1017,
    This can be achieved, but will not utilize HomeSharing. Further information and steps can be found in the following article.
    iTunes: How to share music between different accounts on a single computer
    http://support.apple.com/kb/HT1203
    Cheers,
    Allen

  • Context binding between different components using component interface cont

    Please tell me the procedure how to do context mapping between different components ......
    Please post the procedure ASAP.

    Hi Koti,
               Check this
    <a href="/people/bertram.ganz/blog/2007/01/19/new-web-dynpro-java-tutorial--component-interface-definitions-in-practice:///people/bertram.ganz/blog/2007/01/19/new-web-dynpro-java-tutorial--component-interface-definitions-in-practice
    <a href="https://www.sdn.sap.com/irj/sdn/wiki?path=/display/wdjava/usecomponentsinbiggerWebDynproprojects%28componentization%29&">https://www.sdn.sap.com/irj/sdn/wiki?path=/display/wdjava/usecomponentsinbiggerWebDynproprojects%28componentization%29&</a>
    regards
    Sumit

  • Differentiate between shortcut keys Alpha (keyboard) Enter and Number Pad (10 key) Enter

    I need to be able to differentiate between the Keyboard enter and the 10 key enter (see image below) using a shortcut key in Captivate and/or Flash. These keys are used for two different reasons in the application that I am creating a simulation for.  Using ENTER allows the learner to use either key to continue with the simulation. I would like to force use of each of these keys differently.

    Hi Rastapote, and welcome to the HP Support Forums!
    I understand that you are having a problem with the numeric keypad on your HP Compaq 6830s Notebook PC. This is a business Notebook and you would get the best answer to your question on the HP Enterprise Business Community forum as they deal with the Business products.
    I hope this information helps.
    Have a great day!
    I worked on behalf of HP.

  • How to differentiate between 2 exceptions which are same(Ex: IOException)

    how to differentiate between 2 exceptions which are same(Ex: IOException)
    but occurring in 2 different functions(Ex: one in systemSoftwareProvisioning()
    and other one in provision() ). How to differentiate between them and in the
    framework how to catch both of them separately

    also use throwable.printStackTrace() method, this will point the line no. of the java file where the exception occured

  • Looking for eMac: How To Differentiate Between Models Document

    Hello,
    I have been trying to find an Apple help document about how to differentiate between eMac models.
    I have found an article about iMacs, but can not seem to find one for eMacs. Here is a link to the iMac article, just so you can better understand exactly what I've been looking for:
    http://docs.info.apple.com/article.html?artnum=58669
    Does anybody know of a direct link to a similar article for all eMac machines? That would be amazing; thank you in advance for any help. =) *april

    Hello Dave =)
    Thank you for your help and for responding to my post.. The article you posted would have completely solved my problem, however, I, unfortunately, do not have access to serial numbers, and the serial number is mandatory for identifying eMac models in the article you posted. I appologize for not being more specific about exactly what I need.
    You see, I am looking on eBay for a good, used, possibly older eMac for my mom. Unfortunately, nobody puts serial numbers in their eMac listings, so I can not properly identify and price compare different eMacs. eBay sellers only list such things as Model Name, Processor Speed MHz, SDRAM and Hard Drive GB, so I need a list to 'check against' like the iMac document. I am mostly trying to find out which eMac models came with DVD players, and also which ones are AirPort ready and AirPort Extreme enabled etc.
    Would you happen to know if there's any such eMac model document?
    Thank you again for posting to my question; I do appreciate it. *april
    iMac 15" Flat Pannel 700 MHz PowerPC G4 1GB SDRAM   Mac OS X (10.3.9)   i love my little bubble computer

Maybe you are looking for