A hammer is an object that has a simple method called Hit() that needs three parameters. One parameter that links to the person wielding the hammer, which would be another object. And the nail that is going to be hit, which is also an object. And an optional third parameter for the wall or other object that you want to put the nail into. The Person object would have an Operate() method that accepts a list of objects that will have to operate together. This list would contain the hammer, the nail and the wall. It will examine the objects and notice that the hammer has a Hit() method while the nail has a length and with and material property while the wall also has a material property determining how tough it is. So the Operate() method would have to calculate how hard it needs to hit the nail to get it into the wall. Thus, you would have this function call: Person.Operate(Hammer, Nail, Wall) which then calls Hammer.Hit(Nail, Wall, Force) where Force would just be a float to say how hard the nail gets hit. (In Newton, the unit for force.) Seriously, when you want to learn object-oriented programming, you really have to think in objects…


Es sind noch einige weitere EasterEggs vorhanden. Viel Spaß bei der Suche.

Nach oben