While reading about abstraction, I came across the following statement
“Abstraction captures only those details about an object that are relevant to the current perspective”
For eg.
From the driver’s perspective, Car class would be
public class Car
{
void start();
void applybrakes();
void changegear();
void stop();
}
From the mechanic’s perspective, Car class would be
public class Car
{
void changeOil();
void adjustBrakes();
}
My question,
While designing a system, do we design for one user perspective(either driver or mechanic) or can
we design for multiple user perspective and further abstract out based on user type?
Hope my question is clear.
Thanks
Depending on your use case you might need to deign for multiple users. In your example, if your car will be used by both the mechanic and the driver, then you cannot just ignore one set of users. In that case, you can still abstract details by using Interfaces.
You could design your object like this:
Now, when a mechanic wants the car, you don’t give him a
Carobject, instead give him anIFixableobject. Similarly, the driver gets anIDrivableobject. This keeps the relevant abstraction for both sets of users simultaneously.Similary, a mechanic won’t have access to the methods in the interface
IDrivable.You can read more about interfaces here. Even though this is the MSDN link and uses C#, all major languages support interfaces.