0

Can I hide properties from outside world but not from its creator

I have a dll, that contains a object. This object is also a dll To explain this. The outer object is a Car. This has another object that is an Engine Car Engine Both have a method Start. Both have a method ReportAnError What I like to do is MyCar.Start(); MyCar.Engine.ReportAnError(); To achieve this I have made Engine a public property of the car class. The car-class is the creator of the engine. The outside world likes to know about the error of the engine, but should not be able to start the engine itsself. The method MyCar.Start, should start the Engine with the method Engine.Start. But the following should not be allowed. MyCar.Engine.Start How can I achieve this ? private is seen by nobody public exposes the method start internal makes the method start inaccesible for the car-class protected is not applicable, because this is not about derived classes. Some code to explain the problem https://code.sololearn.com/c96A202a5A17/?ref=app

26th Feb 2021, 11:17 AM
sneeze
sneeze - avatar
1 Respuesta
+ 2
first it does not make scence to have a start method both for the engine and the car. second the myEngine is a property of the the car class so the object of the car class does have access to its property which is MyEngine . thers not an ultra private keyword in c# to hide its properties from its objs as it doesnt make sence.
28th Feb 2021, 7:09 PM
N A I E B I