PS: in this thread nobody has disagreed about what OO programming is.The disagreement was about *how to apply it*.There actually seems to be quite a lot of agreement that theanswer depends on what your underlying goal is:��- is this throw-away code for a specific problem?��- is this code to be included in a useful program?��- is this just for practice in an unfamiliar language�� ��where you already understand all the concepts?��- is this for learning about radically new concepts?And everyone agrees that test cases are good for all of these.
You might find it useful to join another exercism thread andsolve some of these problems in a language that you arecomfortable with, then solve them in Smalltalk (or Ruby).This will help to separate "how do I solve this problem?"from "how do I express this solution in language X?"Another thing you might find useful, having solved aproblem, is to try to solve it a different way.
For example, in a functional language, you might solve aproblem first in a C-like way using mutable objects freely.Then you might solve it again using immutable values.And then you might solve it again using higher-order functions.And then you might solve it again using point-free style asmuch as you can.
For another example, in R, or Fortran 90, or Matlab, youmight solve a problem first in an element-at-a-time way,and then you might try it again using vectorisation toeliminate as many loops as you can.
And in *this* example, don't suppose that there is One RightWay To Do It.�� Get ONE solution going.�� ANY solution.�� I wouldsuggest my approach, because (a) of course I would, and (b) itreally is a struggle with exercism to find out what the problemactually is, and you want to get to SOME solution quickly.�� Butit doesn't matter so much, because the point is to try it MOREways than one.�� This is one way to learn design.�� Try more thanone approach and discover which ones work out better.
I started out using Point.�� Then I tried again just using barecoordinates.�� I started with position and velocity as instancevariables.�� Then I tried again with them as method temporaries.I eliminated one thing after another until I was left withobviously correct code, and I felt no shame in using#caseOf: to classify characters, even though there are booksthat will tell you that using "if" and "case" is anti-OO.I could do it again eliminating #caseOf: in terms of "if" if
I saw any value in doing so.
In this particular exercise, you are simulatingONE instance (the robot) of ONE kind of thing (Robots).That strongly suggests that your solution might haveONE class: Robot, or perhaps TWO: Robot and RobotTest.That's the one active thing.
This thing has properties: where it is and which way itis going.�� Now from the point of view of differentialgeometry, points and directions are different things andlive in different abstract spaces, so I would have a lotof sympathy for having two classes: Place (x,y) andDirection (dx,dy) with #turnLeft and #turnRight asoperations on Direction andplace plus: distance in: directionas an operation on Place returning a new Place.But a good programmer is a lazy programmer, andlooks for existing code to use.�� And the classicPoint class in Smalltalk combines Place and Directionin one "two-dimensional vector" concept, originallydesigned for 2D computer graphics rather thangeometry.�� It's good enough, and Smalltalk programmerscan be expected to know that Point exists (just as Javaprogrammers can be expected to know about Java's pointclasses), so I'd use it.
So now, from one mind, we have designs with1�� Robot2�� Robot, RobotTest3�� Robot, RobotTest, Point4�� Robot, RobotTest, Place, Directionclasses.�� ANY of them could be defended as a good design,depending on what the ultimate aim is.