Abstract method which when implemented will have different parameters

Hello to all,
I have an assignment but not looking for someone to do it for me. I am only searching for a suggestion on how to do the following.
Imagine having an application that needs to provide an estimate of the rent for different buildings.
Basically I start with by having a class name Building. This class has an abstract method called estimateRent.
I then create two classes that extend the class Building which are named Apartment and House. Both need to have the method estimateRent.
However the problem is that the rent for the Apartment is calculated on the nights passed in the flat and the people in it, while the rent for the House is just calculated on a month bases.
This means the estimateRent method requires to have different parameters depending if it is implemented inside the Apartment class or the House class.
Now I only know of two options.
The first option is to not declare the estimateRent method as an abstract method inside the Building class and just implemented inside the Apartment and House with different parameters. I do not like this option since in the future if a new Building comes in then I would like to impose the fact that that object needs to have a calculate method.
The second option is to make the estimateRent method as abstract inside the Building class however takes a parameter of either a String array or else a Map. Then the estimateRent within the Apartment class would search for the elements tagged as nights and people, and the House class would only search for the elements tagged as months!
However do not know if there are any other, better ways on how to do this. I am using Java 1.4 however if you only have answers for Java 5.0 then please post them again since I always like to learn something new :)
Thank You for any comments.
tx

The implementation changes, yes.Yes that I could understand in the Strategy Pattern (in the document I read it was being compared with the Template Pattern).
Then you need to refactor your design.I tought about that, however if you read my first post you will notice that I have different criteria on which the costs need to be estimated. While the costs for a flat are estimated on the people staying in and nights slept there, the costs for the house are based only on the months stayed there regardless of the people living in. Now for me I feel that it is bad programming practice to create one method that can have all the parameters required for any scenario. I mean the following is NOT something I am going to do:
estimateCosts(int nights, int people, int months ... etc);
That's not a very elegant way of going about it.
What is the "Context" going to have?Yep I agree, but so far my limited brain has only come up with that! I am open to any other sugestion! always if i understand it first!
Basically the Context would better be named as Criteria and it would be an interface as follows:
interface Criteria{}
Then I would create two classes that implement the Criteria object as follows:
class AppartmentCriteria implements Criteria{
public Result estimateCosts(int nights, int people);
class HouseCriteria implements Criteria{
public Result estimateCosts(int months);
Now when I recieve the inputs, depending on the scenario the Criteria is typecasted and the correct parameters passed and we recieve the Result.
I feel the above sucks since I am not seeing it as an object oriented way of doing this out! Is there any other sugestions! The refactoring thing I am intrested in! however really I can not see how such a call to that method could be refectored!
Thank You,
tx.
PS: Sun has blocked my other account as well, and this time they did not even send me an email to confirm that I was registered successfuully :( Is there someone I can contact on this? I guess next time I will reply with tx53m :)

Similar Messages

  • How to find port number , when there will be different instance number ?

    In case of portal url,
    port number is 50000 for default instance number 00.
    how to find port number , when there will be different instance number , instead of 00?
    Thanks

    Hi
    You can find the port number by your instance number as follows:
    There is a general format for the port number like you have mentioned.
    For 00 instance the port number is 50000.
    The general format for the port number goes like this:
        <b>5<instance_no>00</b>
    If your <b>instance number is 01</b> then the port number would be <b>50100</b>.
    It depends on the installation type which you perform.
    You can also change the instance number during the installation but normally you dont do this.
    If you have many components or units installed on your system you may have more than one instance in that case it may go like this 00, 01, 02....accordingly port number will be 50000, 50100, 50200...resp.
    Hope this solves your doubt.
    If you need some more clarification please lemme know.
    Regards
      Sumit Jain
    **Rewrd with points if useful.

  • Defining enum with abstract method which returns a generic type

    Is it possible to define an abstract method which returns an geneic type like below? Thanks
    public enum Type{
         A{
              public List<Integer> getData(){}
         B{
              public Set<String> getData{}
         abstract<T> T getData();
    }

    vulee wrote:
    Why not?
    List<Integer> lst = Type.A.getData();Wonder, which compiler you use. Can't be Java6:
    # javac Enums.java
    Enums.java:23: incompatible types
    found   : java.util.Collection<capture#376 of ?>
    required: java.util.List<java.lang.Integer>
                    List<Integer> data = Type.A.getData();
                                                       ^
    1 errorEdit: Unless you do it the generic way as you proposed, which actually is a phoney. Because of the T being a generic method parameter, the compiler will infer it from the type of the variable it gets assigned to. Hence, both of the following will compile:
    List<Integer> lst = Type.A.getData();
    Set<String> lst2 = Type.A.getData(); // Runtime exceptionActually, javac is telling you that giving warnings on the enum constants redefined method return types.
    Edited by: stefan.schulz on Sep 10, 2008 11:38 PM

  • CS5: How to design a text logo that will have different faces of people of different race on it? [was: Help Me Please!!!]

    I am trying to design a text logo that will have different faces of people of different race on it, please how can I develop the text such that the pictures of those faces will be on it?
    Does the picture have to be at the background? Which platform (Photos, Illustrator etc) do I have have to use?
    Someone please help me since I am new with Adobe packages and I use Adobe CS5

    @JJMack
    Thank you for your help
    Please this sound too technical for me
    Can you help me to break this down?
    I have not even design the text of the logo and do not understand what you have text.
    I know what a layer is but I have not yet txt out the Logo text
    As for this: "or layers these can be converted to shape layers and merged if  need be",...  which platform can I do this on please (Photoshop, Adobe Illustrator etc ?
    As for this: "You can then  edit the slape layers path and define a custom logo shape for the edited path",   I need to know the process, will try to see sample on youtube though
    As for this: "Then use the custom shape tool draw out any size logo path you want and use it as a vector mask on image layer".  I will try to get familiar with Vector first and please let me know alternative platform to do this on
    Thanks

  • Any idea when Apple will have a raw converter for the fuji x10

    Any idea when Apple will have a raw converter for th eFuji X10. Might have to switch to Lightroom!

    We are just users like you, so we can only guess - this is a user-to-user forum, sorry. Send feedback to Apple, if you want them to listen.

  • When we will have PR 1.3 for Nokia N900 in UK

    Any news when we will have PR 1.3 for Nokia N900 in the UK ?

    Qas91 wrote:
    ok this sucks, i got the update notification i thought it was pr 1.3 but it was the maemo theme... and qpu freq but i cant upgrade so im guessin i need pr 1.3 to install these upgrades?
    Yep - that's why I went and flashed the phone to Global...Was getting fed up with getting excited to see a yellow "!" and then find I couldn't install half the offered apps...
    If tnis post is a cure to your issue, please MARK IT AS SOLUTION.
    If this post has helped anyone in any way, PLEASE SHARE YOUR KUDOS, by clicking on the GREEN STAR.

  • Any idea when Lightroom will have support for 5D Mark III?

    Any idea when Lightroom will have support for 5D Mark III?

    palashb wrote:
    Thanks Geoff and Jeff.
      On the regular LR updates, will the update be for LR3 also or just for LR4?
    Thx.
    I don't immediately recall a time when the previous version of LR was updated after the next version was released.

  • Where can i go/call to see when ATT will have Iphone4?

    Hello everyone,i would appropriate anyone's insight on the subject line of where can i go/call to see when ATT will have Iphone4?
    Thank you in advanced.
    dxm

    You can check you account at the at&t website or somewhere on here someone had a number you call and a text is sent letting you know.
    Found it and it does work. dial *639# on your phone to find out if you are eligible.
    Message was edited by: caryrae

  • When I will have os X mountain lion, if I buy an app, will I be abble to play the same game on my ipod without buy it again?

    When  I will have os X mountain lion on my imac, if I buy an app, do I will be abble to play the same game on my ipod?

    If you buy an iOS app, it is yours for all your iOS devices. However, some apps are specific for the iPad while others are specific for the iPod Touch or iPhone.
    Mac OS X apps are totally separate and must be purchased separately.

  • Reg. oops...implementation of abstract method in se24...have ur ponts..

    Hi all,
    In SE24 i made an abstract class & made a method abstract successfully.
    Now i made another class that inherited my abstract class, it is showing my abstract method there.
    Now when i want to give implementation to that method, but when i double click on that system is showing "method is abstract & has not yet redefined".
    Pleas let me know..how i implement it..
    Thanx in advance..
    <b>Have ur point.s</b>

    Hi
    Inheritance Inheritance defines the implementation relationship between classes, in which one class (the subclass) shares the structure and the behavior defined in one or more other classes (superclasses). Note: ABAP Objects only allows single inheritance.
    Inheritance is a relationship, in which one class (the subclass) inherits all the main characteristics of another class (the superclass). The subclass can also add new components (attributes, methods, and so on) and replace inherited methods with its own implementations.
    <b>Single Inheritance</b>
    ABAP Objects only has single inheritance.
    A class may only have one direct superclass, but it can have more than one direct subclass. The empty class OBJECT is the root node of every inheritance tree in ABAP Objects.
    <b>Relationship between Superclasses and Subclasses</b>
    Common components only exists in  the superclass
            new components in the supercalss are automatically available in subclass
            amount of new coding is reduced ( programing by difference)
    Subclass are extremely dependent on superclases
           white box reuse – subclass must possess detailed knowledge of the implementation of the superclass
    <b>Inheritance: Syntax</b>
           Normally the only other entry required for subclasses is what has changed in relation to the direct superclass. Only additions are permitted in ABAP Objects, that  is, in a subclass you can "never take something away from a superclass". All components from the superclass are automatically present in the subclass.
    <b>Class name defination.
        public section.
             methods. First name importing some type some type
                                            returning value(value) type some type.
       private section
              data : make type string..
    Endclass.
    Class name1 definition inheriting name
    public section
           method. : get  returning value ( value) type get.
    Priavte section.
       data : max type some type
    endclass</b>
    <b> Redefining methods</b>
    The REDEFINITION statement for the inherited method must be in the same SECTION as the definition of the original method.
    If you redefine a method, you do not need to enter its interface again in the subclass, but only the name of the method.
    In the case of redefined methods, changing the interface (overloading) is not permitted; exception: Overloading is possible with the constructor.
    Within the redefined method, you can access components of the direct superclass using the SUPER reference.
    The pseudo-reference super can only be used in redefined methods.
    reward if usefull

  • When we will go for an abstract class and when we will go for an interface?

    it's always some what confusing to choose an abstract class and an interface,can anybody post a suitable answer for this.

    jwenting wrote:
    with experience and the insight it brings, you will know which to use when.
    Without it, it can't be explained.
    More often than not there's no X OR Y anyway.It's fortunate that there are posters here who possess the insight and experience necessary to explain this. The principal differences between an abstract class and an interface are,
    1. An abstract class can carry implementation, whereas an interface cannot.
    2. An abstract class is singly inherited, wheras an interface is multiply inherited.
    So use an abstract class when the implementation it can carry outweights the fact that it cannot be multiply inherited That's the gist of it.
    The inheritance relationship where this happens is when the supertype is a general concept of which all potential subtypes are special cases. This is called a specialization (or sometimes a generalization) relationship. For example Apple and Banana are Fruit. Or Car and Bike are Vechicle. The Fruit and Vechicle supertypes are general concepts of which their subtypes are special cases. In this case make Fruit and Vechicle abstract classes because the subtypes will benefit from a shared implementation.
    If you don't have a clearcut specialization/generalization relationship make the supertype an interface. An example could be the Comparable supertype. The potential subtypes aren't supposed to be specializations of the Comparable concept, they're suppose to become Comparable (and make this property an integral part of their being). This is not a specialization/generalization relationship. Instead the supertype is intended to add character to the subtypes. The subtypes are unlikely to benefit from an inherited implementation. So make Comparable an interface.

  • Keynote is an amazing tool for preparing presentations.However, keynote for iOS devices(e.g. iPad) doesnot have the simple way to add audio files in to the files.When we will have the update to add music files right into the keynote slide?

    I have been using Keynote for presentation slides to be used in conducting training sessions. Though, Keynote has beautiful interface with elegant transitions to animate, it doesnot provide any way to add audio or music files into the slides in iOS devices alone. I have been waiting for the update to add this very feature,but cannot find it yet.When could we have this upate?

    Send Apple feedback and tell them what you want. However, many app versions of programs are skinnied down, and that functionality may not be workable in the App version. Can't know until you suggest it to them however.
    Lower right corner of this page, the contact us link, give it a try.

  • I cannot send emails; looks like my smpt parameters are wrong; what difference is there between my incoming and outgoing servers and should they have different parameters (ID and password)?

    I cannot send emails; looks like my smpt parameters are wrong?? What difference between the incoming and out coming servers? Do I have different user names and passwords?
    I would appreciate some assistance
    Thanks

    I cannot send emails; looks like my smpt parameters are wrong?? What difference between the incoming and out coming servers? Do I have different user names and passwords?
    I would appreciate some assistance
    Thanks

  • Firefox frequently freezes. I can't click on anything (tabs, menu buttons, bookmarks, etc.) The only button that works is the upper right close button which when clicked will ask me if I want to "save & quit." Then I have to restart. Help fixing this?

    Frequently when I use Firefox it will all of a sudden freeze. It no longer will accept any user input from the keyboard or mouse. I cannot click on any of the open tabbed pages I have or on my bookmarks or any of the menu buttons. Nothing works. When it happens if it is loading a page it will just freeze in the middle of loading it. I've tried to see if the freezes are caused when it loads certain types of content (java, flash, etc...) but there seems to be no rhyme or reason as to when it happens or with what types of pages. I cannot find a pattern. The ONLY button that works is the close button in the upper right hand corner (X). I can click on that and then Firefox will prompt me with it's regular message asking me if I want to save and quit, quit, or cancel. I'll hit save and quit and then reopen Firefox. It opens my tabs and if I was in the middle of a post it generally will still remember the text I've typed (except Facebook!).
    It's beginning to drive me nuts and I'm really hoping to find a fix to this.

    You will also notice that your shift key will be emulated. Meaning that keys you will try to press will press but they will act like you are pressing the shift key when you are doing them.
    Try this, minimize the firefox window by pressing the tab on your taskbar. After doing that maximize it again. You will magically be able to click any link on your page. When you navigate to a new page however, the entire situation will start all over. My only remedy is rebooting and hoping it doesn't happen again soon.

  • HT2534 When I change my counrty to the US it asks me for a payment method which I don't have. What should I do to continue without one?

    My problem is that I have an account that was set up for the country Kuwait and now I want to change it to the US (or UK) so I can use iTunes store cards but when I get to the payment info there is no “none” option! And i can’t go back and download a free app because I would cancel the country change and return to the Kuwaiti app store.
    Thanks.
    --ta1ba

    Well can you explain my sisters' and everyone elses' US accounts that I made with a bogus address? I use my country's address with the zip code 12345 because we don't have zip codes here. Also the fact that my brother uses his Irish account here in Kuwait.

Maybe you are looking for

  • ITunes on XP unsupport Vunerable?

    Hello Friends, I am on an XP machine and now unsupported, what can I use for a calendar that iTunes will sync with? I had thought of trying to use iCloud, (in the clouds), meaning not on my machine, but how can that work? For instance I have always t

  • Spry MenuBarHorizontal not working in IE7

    Hi, I'm new and this is my first post. I cannot get the Spry Horizontal Menu Bar to work in IE. http://educationaltools.org/codnew/default.html Please help! Thank you! Lisa --UPDATE-- I  updated to Spry Prerelease 1.6.1 and it seems to be working. No

  • Is there a difference in Premier and After Effects Performance in terms of intel or AMD?

    Is there a difference in Premier and After Effects Performance in terms of intel or AMD?  Forget the speed issue, assume that the processors are of comparable speed and also assume that the system is built beyond recommended requirements.  When it co

  • Photo Viewing Question

    I come from a fragmented Apple family. I have an itunes account on my computer at work. One daughter has her itunes account on her laptop and another daughter has her itunes account on family PC. We all three have Iphones. My wife would like an Ipad

  • Error while updating Infotype

    Hi I am currently hiring an employee Through PA30  by maintaining IT-0000,IT-0001 and IT-0002 . Now what I want is that if I get an error in maintaining any of these Infotypes I want either all to get updated at once or none at all. So if I get an er