3 ms·
The backward subject-verb semantics in the OO examples are typical anti-OOP straw men. It doesn't have to be Room.look() and Object.examine(), when it could sim
by snorkel 16y ago
The backward subject-verb semantics in the OO examples are typical anti-OOP straw men. It doesn't have to be Room.look() and Object.examine(), when it could simply be Player.look(Room), Player.examine(Object), Player.put(Meat, Basket), etc. Don't begin with a design pattern then write code around that poorly choosen pattern. Instead write your core logic expressions first then it becomes obvious what the structure of each object ought to be.
- chbarts 16y agoThe concept that all OO is based around message-passing is almost an anti-OO straw man, except that message-passing is still considered to be the 'default' OO style. It's hard to call it a straw man when even the experts seem to take it for granted. OK, so what would I propose? CLOS-like generic methods with full multiple dispatch and specialization. That would solve the problem you solve with the 'Player.put(Meat, Basket)' syntax by replacing it with 'put(Meat, Basket)' or, at worst, 'put(Player, Meat Basket)'. The advantage of this is that every time you need to put a new kind of thing, you only have to update one method, as opposed to updating the 'put()' method in everything that knows how to 'put()'. In CLOS, methods dispatch on all their arguments. There is no special God Object or God Class that knows way too much about what's going on, as your Player class would seem to. This is achieved by specializing the methods: Creating a new method with a different type signature for each object combination it will have to handle. As a result, each class of functions knows what it has to know, and objects are just places to store data with type information attached. However, this might be the case of the good being the enemy of the best: Obviously, a good domain-specific language is an absolute maximum for any problem domain, and I7 is a good text-adventure DSL. Moving from Javascript to Common Lisp wouldn't be nearly as good of a deal.