Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

OO is not that great[2]: repeatedly passing the same member reference

Thread view: 
Shawn - 22 Sep 2006 19:20 GMT
Hi,

I have several classes TellerA, TellerB, TellerC and BankAccount.
TellerA and TellerB and TellerC are working like in a chain. TellerA
does something to the bankaccount object and pass it to TellerB. TellerB
does something to the same bankaccount object and pass it to TellerC.
There is only one object of BankAccount class, which everybody works on
it. So TellerA, TellerB and TellerC all have a member reference to a
bankaccount and passing the object bankaccount is very deliberate and
redudant.

public class TellerA
{
    BankAccount myAccount = new BankAccount("1 million");

    ..// did something to myAccount

    TellerB b = new TellerB(myAccount, parameter A, parameter B); //I feel
the parameter myAccount is so redundant

}

public class TellerB
{
    private BankAccount ac = null;

    //constructor
    public TellerB(BankAccount ac, parameter a, parameter b)
    {
        this.ac = ac;
        ...// do something to the bank account -- same account object
        ...//then pass it to TellerC who keeps working on it
    }
}

As you see, both TellerA and TellerB are working with the same account
object. But the object has to be passed deliberately. In procedural
language, you can leave the object in the global place and let everybody
access it, modify it, like a chain in a factory.
opalpa@gmail.com opalinski from opalpaweb - 22 Sep 2006 19:36 GMT
If you want to, you can have global data by using public static fields.

Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.