[Solved] Methods using arguments vs member variables [closed]


The class in OOP is something which describes an object. Take a real world object for example, a car. The car can have functions like accelerate_to_speed(double speed); and some members like Color color;. The methods are something the object does and the members describe the object or show possession (the car can have an engine Engine engine;). The whole concept of what is a member and what is a method lies at a foundation of object oriented programming and is not dependent upon language but the language is dependant upon it.

You could still write a class car in this way:

class Car {
    ...
    double target_speed;
    ...
    void set_target_speed(double speed) {
        target_speed = speed;
    }
    void accelerate_to_speed() {
        current_speed = target_speed;
    }
    ...
}

And the language would allow it but what does it mean? Is the car described by what the target speed is? What does the target speed mean if the car is not used?

solved Methods using arguments vs member variables [closed]