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

Discussion in 'Java' started by Shawn, Sep 22, 2006.

  1. Shawn

    Shawn Guest

    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.
     
    Shawn, Sep 22, 2006
    #1
    1. Advertising

  2. opalinski from opalpaweb, Sep 22, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sam pal
    Replies:
    3
    Views:
    547
    E. Robert Tisdale
    Jul 16, 2003
  2. Shawn
    Replies:
    5
    Views:
    338
    Hendrik Maryns
    Sep 25, 2006
  3. Eric I.
    Replies:
    0
    Views:
    261
    Eric I.
    Oct 5, 2008
  4. Richard Shewmaker

    Return focus to same pop-up window repeatedly

    Richard Shewmaker, Jan 19, 2006, in forum: Javascript
    Replies:
    13
    Views:
    160
    Pierre Sudarovich
    Mar 3, 2006
  5. Wolfgang Maier
    Replies:
    14
    Views:
    133
    Mariano Anaya
    Oct 30, 2013
Loading...

Share This Page