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

S

Shawn

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top