I have two different classes namely Car and Radio.
How I can make sure that class Radio can be only used by class Car?
Or is there better implementation here?
I’m coding in c#.
class Car
{
// car has a radio
}
class Radio
{
// some properties
// some methods
void TurnOn(bool onOff) { }
}
Thanks in advance.
Radio would be a logical modeling if you wanted to use the radio in other places. If you only want to use whats provided by Radio in Car then maybe its not deserving of a class yet and you are overdesigning here. If you do want to limit the Radio to be only usable in Car you could declare radio in the class of car. Its not great but its an answer 😛