Would this case be considered an OO problem?

Hi!
Suppose that some developers and programmers, say programmers of the group A, created the following interfaces:
public interface BankInformation {
  int getYearOfConstruction();
  //and other methods related to bank
public interface CompanyInformation {
  double getCompanyPrice();
  //and other methods related to company
public interface GovernmentInformation {
  Date getBeginningDate();
  Date getEndDate();
  //and other methods related to government
/* and other kinds of useful interfaces... */And others, say programmers of the group B, created the following very useful class (for the group B):
public class Informations {
  private String usefulInformation;
  public void setRelevantInformations(BankInformation bi) {
    int i = bi.getYearOfConstruction();
    String something = null;
    //etc...
    //doing something based on BankInformation...
    usefulInformation = something;
  public void setRelevantInformations(CompanyInformation ci) {
    double d = ci.getCompanyPrice();
    String something = null;
    //etc...
    //doing something based on CompanyInformation...
    usefulInformation = something;
  public void setRelevantInformations(GovernmentInformation gi) {
    Date initialDate = gi.getBeginningDate();
    Date endDate = gi.getEndDate();
    String something = null;
    //etc...
    //doing something based on GovernmentInformation...
    usefulInformation = something;
  //and other useful methods...
}Now both group A and B are implementing those interfaces, without any kind of design problems untill now:
/* here, classes that implement the interfaces */
public class BankOfBostonInfo implements BankInformation {
  public int getYearOfConstruction() {
  //and other things...
public class SantanderInfo implements BankInformation {
  public int getYearOfConstruction() {
  //and other things...
public class McDonaldsInfo implements CompanyInformation {
  public double getCompanyPrice() {
  //and other things...
public class MicrosoftInfo implements CompanyInformation {
  public double getCompanyPrice() {
  //and other things...
public class GeorgeBushInfo implements GovernmentInformation {
  public Date getBeginningDate() {
  public Date getEndDate() {
  //and other things...
public class BillClintonInfo implements GovernmentInformation {
  public Date getBeginningDate() {
  public Date getEndDate() {
   //and other things...
/* and other kinds of useful classes... */The problem happens now: other group of programmers, say group C, develop a class that implements all those interfaces (why not?), like below:
class AdministrativeInformations implements BankInformation, GovernmentInformation, CompanyInformation {
  public int getYearOfConstruction() {
  public double getCompanyPrice() {
  public Date getBeginningDate() {
  public Date getEndDate() {
  //and other useful things...
}Since it makes sense for group C, why not implement all those interfaces at the same time?
But, unfortunatelly, group C do not know about the Informations class, created by group B. And one day, group B will say to group C: "Hey, give us an instance of your AdministrativeInformations class, we need it!".
Group B will have a problem now, because when they use setRelevantInformations() method, which is the parameter they have to pass? They cannot pass an instance of AdministrativeInformations class, and they cannot cast, because setRelevantInformations() method works according to the parameter passed. Certainly, they cannot specify and cast to BankInformation, GovernmentInformation or CompanyInformation, because they simply are not able to decide which type of interface they have to consider.
And if group B decide to discuss about this problem with group C, to solve that, group C won't be able to help, because group C will say "this is a problem of group B, only. It is not our problem". Or group C could rewrite their AdministrativeInformations class, but obviously they would not like this idea.
Might this situation be considered a design problem, that could have been prevented, or is this situation just an unlucky OO problem, that might occur and nothing can be done to prevent that? I would like to read your comments.
Many thanks!!!

I'm going to hazard an answer here and suggest the problem lies with the original design of the "Informations" class. As itchyscratchy pointed out, the problem lies within the fact that the setRelevantInformations method is overloaded and, as a result, assumes that being a BankInformation (for example) is mutually exclusive with being a CompanyInformation.
I find myself asking what precisely it is that the setRelevantInformations(...) methods are doing with that data and I would resolve this issue in one of two ways. The first is to simply rename the methods ("setBankInformation(...)", "setCompanyInformation(...)", etc.); this presumes that the operation which is being performed is unique to the Informations class and doesn't really directly have anything to do with the BankInformation, CompanyInformation, or GovernmentInformation interfaces. The structure of the Informations class as is implies that being a BankInformation is exclusive with being a CompanyInformation. Even if this is not the case, calling setBankInformation is definitely exclusive (at any instant, anyway) with calling setCompanyInformation.
The solution I would prefer, however, would rely on the operation being performed by each of the setRelevantInformations(...) methods having something quite directly to do with the objects themselves: that is, that the operation and the object are somehow conceptually linked. For example, they seem to be producing a string in this snippet. In that case, I would make:
public interface BaseInformation {
    public String makeInformationString();
public interface BankInformation extends BaseInformation {
    int getYearOfConstruction();
public interface CompanyInformation extends BaseInformation {and so on. Then, I would modify the Informations class:
public class Informations {
    private String usefulInformation;
    public void setRelevantInfomation(BaseInformation bi) { ... }
}Whatever operation the setRelevantInformations(...) methods were performing have now been abstracted into a single method. Once again, this eliminates the need for overloading. And, of course, this would only be appropriate if the operation being performed (in this case, "makeInformationString") is somehow related to the interfaces themselves and not just to the Informations class.
In summary, it seems that abuse of overloading is the problem. I can't quite put my finger on exactly how the overloading has been abused in this case, but that's probably due to a combination between lack of specific information and lack of sleep. :)
Cheers!

Similar Messages

  • Would this be considered a hack???

    Hi,
    on ehow.com they teach you how to make ringtones for your iphone within itunes itself.
    i want to know, would this method be considered a hack? because it's not really hacking into the phone or itunes, its really just going around and finding the holes and using them to your advantage?
    http://www.ehow.com/how2160460custom-iphone-ringtones-free.html

    No, it's perfectly fine to use those steps to create a ringtone. Note that the method +does not+ work with DRM-protected music (which is appropriate).

  • What is the cost of replacing a battery for an Ipad 2 in India? On asking the service centre, I was informed the entire Ipad would be replaced for 20K which is exorbitant. Is it advisable to buy the Apple protection program in this case?

    What is the cost of replacing a battery for an Ipad 2 in India? On asking the service centre, I was informed the entire Ipad would be replaced for 20K which is exorbitant. The same is done in US for a paltry (comparably) 100 dollars. Is it advisable to buy the Apple protection program in this case?

    Battery Replacement
    http://www.apple.com/batteries/replacements.html

  • I replaced my hard drive and used time machine to boot from but it installedthe unrepaired disk permissions of the faulty previous drive would this cause problems on my new drive?

    I replaced my hard drive on macbook pro and used time machine to boot from but it also installed the unrepaired disk permmissions of the other drive, would this cause problems to my new drive?

    Can you remember what the permissions problem was that you had before? You may need to reinstall OS X from scratch and not reinstall anything from your Time Machine backups. To be on the safe side you should reinstall all third-party applications from scratch, as well. Then only restore from your backup your document/data files.

  • Using iDVD, I've no problem creating a slideshow, but I want to add three seperate sound files, in this case speeches I've got in iTunes. I want to create three individual buttons/sub menu to access them individually from the photos. Can anyone help

    Using iDVD I've no problem creating a slideshow, but am having problems trying to add three seperate sound files in this case three speeches that I hold in iTunes. I want to be able to access them individually and seperately from the photo slideshow. Can anyone advise if this can be done and if it can, how I go about creating the seperate menu and buttons.

    If you'd like to integrate the speeches with the slideshow, I'd do that in iMovie where you'll have more control over the timing.  Use chapter markers at the beginning of each speech so the viewer can jump to a particular speech (note that chapter markers advance the viewer to a particular spot -- the viewer keeps watching the rest of the video until the end of everything or until they use the remote's menu button).
    If you're just wanting the speeches to be on the DVD so people can listen to the speeches after seeing your slideshow, you could:
    - use iDVD or iMovie to make a "slideshow" with just 1 image matching the length of a speech.
    - create three submenus and use the speeches as menu music.  Here's a (random) video on creating submenus:
    http://www.youtube.com/watch?v=DlhQSb_D5kc
    John

  • Hello, I live in Russia and would like to purchase I-phone through the online store E-bay from a private individual. As in this case, the guarantee?

    Hello, I live in Russia and would like to purchase I-phone through the online store E-bay from a private individual. As in this case, the guarantee?

    Again, the iPhone warranty is NOT international. And, if I may offer unsolicited advice, buying from ebay is always risky. Most sellers are less then honest when it comes to iPhones. They might state that the iPhone is unlocked when it is not; it might not be really unlocked or might be hacked/jailbroken.
    My advice to you is to buy in the country you intend to use the phone and buy it from a legitimate source such as Apple or an authorized reseller.

  • I have problem with my I PHONE 4S  Always its time out then i must restart my I phone please any help about this case ??

    i have problem with my I PHONE 4S  Always its time out then i must restart my I phone please any help about this case ??

    Hello Pllumb,
    It sounds like you are unable to turn on Wi-Fi because the option is grayed out in Settings. Use these steps from the following article named:
    iOS: Wi-Fi settings grayed out or dim
    http://support.apple.com/kb/ts1559
    Restart your iOS device.
    Make sure that airplane mode is off by tapping Settings > Airplane Mode.
    Reset the network settings by tapping Settings > General > Reset > Reset Network Settings.
    This will reset all network settings, including Bluetooth pairing records, Wi-Fi passwords, VPN, and APN settings.
    Make sure that your device is using the latest software. To do so, connect your device to your computer and check for updates in iTunes.
    If you still can't turn Wi-Fi on, please contact Apple for support and service options. If you can turn Wi-Fi on but are experiencing other issues with Wi-Fi, please see these steps.
    Thank you for using Apple Support Communities.
    All the very best,
    Sterling

  • When i save any image from any website then there is no option showing in the save as box like saves as .jpg etc. In this case I manually add the extension of image for example .jpg .gif etc. Please solve my problem :(

    When i save any image from any website then there is no option showing in the save as box like saves as .jpg etc. In this case I manually add the extension of image for example .jpg .gif etc. Please solve my problem :(

    I'm guessing your problem is caused by code validation errors: orphaned division tags for example, or mismatched code and document type (i.e.  XHTML /> mixed with HTML > style closures).
    Start by using the code validation tools below and fix any reported.  You'll need an Internet connection for this:
    HTML Validator - http://validator.w3.org 
    CSS Validator - http://jigsaw.w3.org/css-validator/  
    HTML & CSS Tutorials - http://w3schools.com/
    If this doesn't solve the problem, you will need to post a URL to your live page so we can see your code and images working together.   Or at the very least copy and paste your HTML and CSS code into a reply using double arrows >> Syntax Highlighting > Plain.
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    www.alt-web.com/
    www.twitter.com/altweb
    www.alt-web.blogspot.com

  • Hi , i'm new here and i would like to ask a question about iPad 2 . Well , actually when i hold my finger on any icon , its not jiggling , i need to fix the icons . May i know what can i do in this case ? thank you in advance ,

    Hi , i'm new here and i would like to ask a question about iPad 2 . Well , actually when i hold my finger on any icon , its not jiggling , i need to fix the icons . May i know what can i do in this case ? thank you in advance ,

    Try a reset. Hold the Sleep and Home button down for about 10 seconds until you see the Apple logo. Ignore the red slider.

  • I cannot update my iPad and notes it cannot be updated due to unknown error (6). I have not yet updated my Macbook to Yosemite (which I do not intend to do so yet) so would this be the problem and if so, how can I update the iPad?

    I cannot update my iPad and notes it cannot be updated due to unknown error (6). I have not yet updated my Macbook to Yosemite (which I do not intend to do so yet) so would this be the problem and if so, how can I update the iPad?
    Thanks,
    glhiker

    Hi glhiker,
    I understand that you may be having some issues with your ability to update your iPad. Here is an article that references your error code and can help you take some steps to resolve it:
    Resolve iOS update and restore errors - Apple Support
    http://support.apple.com/en-us/TS3694
    Check your security software
    Related errors: 2, 4, 6, 9, 1000, 1611, 9006. Sometimes security software can prevent your device from communicating with either the Apple update server or with your device.
    Check your security software and settings to make sure that they aren't preventing a connection to the Apple servers.
    Thanks for coming to the Apple Support Communities!
    Regards,
    Braden

  • This is just to report a problem with Apple updates. I updated recently and the computer brought up my 2012 desktop with all my 2014 files and data including stickies missing! Now I hesitate to do another Apple update. What would you do?

    Apple Updates: This is just to report a problem. I updated recently and on restart the computer restored up my 2012 desktop with all my 2014 files and data including stickies missing!!! Now I hesitate to do another Apple update. What would you do?

    If all your files are missing
    You may have logged in as a different user, such as Guest. Open the Users & Groups pane in System Preferences. Your name should be at the top of the user list, under Current User. See also this support article.   
    If files are missing from one folder
    Change the Finder view mode; for example, from icon view to list view, or vice versa.
    If files are present, but seem outdated
    You may have started up from a different volume (disk.) Open the Startup Disk preference pane and check the selection.

  • Would this be considered an upgrade or a downgrade?

    _Right now I have_:
    2-year old Mac Pro
    2 x 2.66 Dual-Core Intel Xeon
    4 GB RAM 667MHz DDR2
    OS X Tiger 10.4.11
    _I am considering selling it and getting_:
    Brand new iMac
    2.66 Intel Core 2 Duo
    4 GB RAM 1066MHz DDR3
    OS X Leopard 10.5.6
    Performance-wise, would this be considered an upgrade or a downgrade?

    Booting would perhaps be faster on her system if it has less RAM. The system goes through a power-on self test which will take longer with more RAM. She could also have fewer programs launching on startup.
    Web browsing might be faster on hers for a number of reasons: different versions of browser (the Safari 4 beta, for instance, is much faster than earlier version or just about any other browser), a faster Internet connection, etc.
    She could have a different version of GarageBand which would be faster.
    There are just too many variables to offer much of anything further in the way of advice. Unless you had exactly the same software load - the same version of OS, the same versions of applications, etc. - it's really difficult to say why her system might be faster, or why you might perceive that it's faster.

  • Is this plsql function considered ok?

    Is this plsql function considered ok?  The reason I am asking is because the results differ when called inside of a package vs calling inside of a procedure.  I am not sure if this is a bug or if it is illegal.
    CREATE OR REPLACE package body test as
    function test return varchar2 is
    begin
    htp.prn('ABCDEF');
    return 'xyz';
    end;
    end;
    When this function is called inside of a package, the string 'ABCDEF' is displayed out of sequence.   I think it is due to 11g inlining the function at compile time.
    Whereas, when the function is called inside of a procedure the string 'ABCDEF' appears in the browser's html correctly.
    Technically the function is doing procedural stuff by output htp.prn data, so Oracle may considered it illegal.  I have a very good reason for wanting this functionality, so before taking another approach I wanted to ask around.

    brian.mcginity wrote:
    'Out of sequence' is a bit vague...sorry.   I probably could create a calling package and procedure which shows the problem.  The place where this is happening in production code is in the middle of a bunch of unrelated business logic.
    Let me try to explain before going down the route of writing a test case.
    The function:
    CREATE OR REPLACE package body test as
    function test return varchar2 is
    begin
    htp.prn('!!!! inside of function !!!!');
    return null;
    end;
    end;
    This is how function is used in a different package:
    htp.p('This is line 1');
    if true then    
         open q for select * from dual;
    end if;
    htp.p('This is line 2.  '||  test.test() ' ||'<br>')
    htp.p('This is line 3');
    So the expected output when you view source in the browser should be:
    This is line 1
    This is line 2 !!! inside of function !!!! !!!! inside of function !!!!!!!! inside of function !!!!
    This is line 3
    However when this code is run inside of a package the output is out of sequence:
    This is line 1
    !!! inside of function !!!!
    This is line 2
    This is line 3
    No, what you're expecting as output is not what I would expect as output.  I would expect the output that you are considering to be 'out of sequence'.
    If you want the first output then your test function should simply be...
    function test return varchar2 is
    begin
      return '!!!! inside of function !!!!';
    end;
    so that it's not writing to the HTP buffer. (as Billy explained in his reply)
    Now take the exact same code block and run it inside of a stand alone procedure:
    htp.p('This is line 1');
    if true then    
         open q for select * from dual;
    end if;
    htp.p('This is line 2.  '||  test.test() ' ||'<br>')
    htp.p('This is line 3');
    and the output is correct:
    This is line 1
    This is line 2 !!! inside of function !!!! !!!! inside of function !!!!!!!! inside of function !!!!
    This is line 3
    When the function is placed inside of a package, the results are different than when inside of a stand alone procedure.  I have a handful of procedure which was calling test.test() and all was working fine.  Then one day when I called test.test() from a package, the output was jumbled.  I narrowed down the problem and quickly created a procedure which did the same thing as test.test() and it fixed the problem.  I still would have liked to use the function version if possible (long story why--don't really want to go into details).
    If that's a difference you're getting between executing the function through a procedure and a package, then there must be something you're not showing us.  There's no good reason for the function to act differently depending on it being in a procedure or packaged.
    You're going to have to provide a reproducable test for people to see exactly what the issue is, because what you've posted cannot be reproduced.

  • Do I need to declare a transaction in this case?

    I am struggling to understand when it is necessary to declare my own transaction to ensure the data is properly updated.
    For example, in the following code, which is part of a java bean in the EJB project, KeyFacade is a stateless session bean tied to the entity "Key". it is a standard EJB created with the netBeans 5.5 wizard. I have changed no defaults.
    Do I need to declare a transaction, commit the transaction and close it when I use the "KeyFacade.edit(key);" in order to ensure the database is updated? Or is it automatically done because the .edit() method uses the entityManager and the persistence is container managed?
    Would it make a difference if this bean was part of a WAR project?
        public BigInteger getNextKey(String tableName){
            KeyFacadeLocal KeyFacade = this.lookupKeyFacade();
            Key key = KeyFacade.findByTablename(tableName);
            long nextKey = key.getKeyvalue();
            BigInteger BINextKey =BigInteger.valueOf((int)nextKey);
            //  now update the table by incrementing the key value by 1
            long incrementKey = nextKey + 1;
            key.setKeyvalue(incrementKey);
            KeyFacade.edit(key);
            return BINextKey;
        }

    808239 wrote:
    I have a Map<Integer, List<T>> data, and all the lists are initialized using Collections.synchronizedList().Seems like overkill to me. Your Map also looks like a Multimap, of which there are several existing implementations.
    When I do the traversal, I want to traverse ALL lists in the map at the same timeI suspect not. What you want to do is to traverse each one in sequence.
    so I have to sync all lists as shown in the API doc as follows: ...Seems like overkill to me, and will probably result in a very slow Map (not that there's any problem with that if it's the right thing to do; in this case, I suspect it isn't).
    Is this approach ok?What are you trying to achieve? If you need full consistency for your iterators (ie, a snapshot of the entire Map at the time the iterator is created), you have a two choices (assuming you don't want to deal with update journals):
    1. Lock the Map.
    2. Clone the Map (and your clone() method should be synchronized).
    Of the two, the second seems best to me, but neither is all that wonderful.
    However, if all you need is weak consistency - that is to say, what you return reflects the state of the Map when Iterator.next() is called - all you really need to do is make sure that your Lists are synchronized when you do the read.
    Since the List updates are the responsibility of your Map (I'm still presuming this is some sort of Multimap implementation), there's no real need to synchronize them; just synchronize the Map's own update methods.
    I'd also suggest that you make sure your getValue() method hands back an [url http://download.oracle.com/javase/6/docs/api/java/util/Collections.html#unmodifiableList%28java.util.List%29]unmodifiable List to clients; otherwise they could start adding or removing values themselves.
    HIH
    Winston

  • Iphone 6 automatically turn on even not connect to charger, why would this happen and how to solve it?

    iphone 6 automatically turn on even not connect to charger, why would this happen and how to solve it?

    I'm not an apple expert or anything, but after hearing this from a coworker (and doing a quick google search) many of the generic chargers do not work in the 5s (especially after the most recent update.) I'm thinking this may be the problem in your case...the charger is not working so the phone just needs a good charge from either an apple certified charger or a generic that will actually work with the phone. I've read some people are able to pull the cable out, turn it around and then plug it back in facing the opposite direction to get it to work. Many have reported, however, that even when this remedies the cable issue, its still won't charge the phone while it is completely dead (which is likely the case since it won't power on at all.) So if you haven't fixed your problem by now, go buy a new charger and see what happens. You might be able to go into and apple store and borrow a charger there for a few minutes to see if this actually IS the problem. That way you don't waste your money before buying.

Maybe you are looking for

  • Itunes will not manually sync music with my Iphone 5

    I am trying to manually sync music from ITunes and my Iphone5. From the Info screen I have selected the option to manually sync music and video files. From the music screen I have selected the option to sync selected artists, etc. I selected some of

  • JDBC To IDOC Multiple segment

    Hi All, We have the requirement to  Create multiple segment which is under  one header if header change it create new idoc else it should add new  line item in same segment of  idoc. Please suggest me Mapping Logic. Regards Laxmi Bhushan

  • Error in QCI during 561 stock upload

    Hi, I am trying to post a GR using MB1C 561, while QCI calculation I am getting an error wchich says "Base temparature is not 60 F". The error is not descriptive so I am not able to figure out whats missing in config/master. Can anyone help? Regards,

  • Mac OS X Lion - Announced monday 7th June?

    Does Steve Jobs announce the new operating system monday 7th june? Thank you for any answers! P.S: English is not my main language...

  • Nokia X3-02 wrong SMS Date

    Hi All! When I receive an SMS, the display show the date of receive it on my phone and not the date send of the sms. This appen when I turn on the phone. Is a very issue and bug. Did you have the same problem? In the future can Nokia correct this bug