points to a repository with C# code, so I cannot comment on the Smalltalk.There is, however, a striking thing about the C# code, qua C#, that isworth mentioning.
It is not encapsulated.
Let's start with the most obvious one.A bank account has a password, and you aresupposed to provide the right password in orderto get information from it.
Your interface *reveals* the password, somalicious code can do���� var pass = theBankAccount.password;and then provide the password back.�� What'sneeded is something like
�� var balance = theBankAccount.queryBalance(pass);
where passwords go *in* to theBankAccount but never everever come *out*.
Another thing is that a BankAccount belongs to a specificCustomer.�� There's a good way and a bad way to manage this.The bad way is for the caller to create a new account thatbelongs to nobody, and then *tell* the Customer "here is anew account".�� With this interface, you could tell anynumber of Customers that they own the account.�� That'spossible in the real world, but in the challenge, it isn't.The good way is to *ask* the Customer "please create a newaccount and tell me what it is", and have no way to forcea Customer to accept an account willy nilly.�� That way aCustomer can be certain that the accounts it is holdingbelong to it and it alone.
Or it could be were it not for a major encapsulation issue.The idea of encapsulation is that�� EVERY CHANGE TO AN OBJECT'S STATE MUST BE MADE BY THAT OBJECTincluding the start of owned containers.
In Java, for example, you might have���� public class Customer {���������� private final ArrayList<Account> accounts = new ArrayList<Account>();���������� ...���������� public List<Account> getAccounts() {���������������� return Collections.unmodifiableList(accounts);���������� }���������� ...���������� public Account newAccount(...details...) {���������������� final Account a = new Account(...details...');���������������� accounts.add(a);���������������� return a;���������� }���������� ...
���� }If you are going to provide access to a collection,(1) make the collection immutable in the first place, or(2) return an immutable view of it, or(3) best of all, DON'T provide access to the collectionbut provide queries that extract just the information youwant to make available.
This has nothing to do with Java or Smalltalk or C# as such;encapsulation is object-oriented-programming 102.
For what it's worth, I used to be a University lecturer, andit was MUCH harder for students to grasp encapsulation thanto grasp recursion.�� I have no idea why.�� Just pretend that youare a nice little object surrounded by malevolent pranksterswho can force you to do anything in your interface, and makesure they cannot harm you.
Oh, when I asked about the source of the challenge, what I wasgetting at was "is this your paraphrase of the challenge, inwhich case please tell us to find the original, or is thisthe actual unmodified original text, in which case --ing h---,you have my profound sympathy."
This looks like a garbled version of an exercise that I dida little over 10 years ago, which I found in a Java-based bookwhose details I unfortunately forgot to record.�� Right down tothe names of the classes!�� That is why I am pretty sure thatthere is a description of the problem somewhere that makes sense.