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.
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.