2 ms·
But the thing is that now the car has to know about the world. If there's a wall on the driver side how can it open the door? I'm not dogmatic on OOP vs FP, bu
by hnedeotes 6y ago
But the thing is that now the car has to know about the world.
If there's a wall on the driver side how can it open the door?
I'm not dogmatic on OOP vs FP, but let me take the side of FP here, we could model this as the car being a data structure with its position (x, y, etc), and a representation of what opening the door is (width of the car + length of the door, an anonymous function, or a named function, that can be made polymorphic) and now our open_door(car, world) can take both and the world doesn't need to know about what is a car and the car doesn't need to know about the world either, it just serves as a mapping, and the function open_door checks the positions of car in the world, transforms the car according to its procedure and checks it still fits the world and if not it produces an annoying beep.