Now, is there a way to create a HAS-A relationship between C # classes, which is one of the things I would like to know - HOW?
Make one class with a field of another class:
class Car { Engine engine; }
The car has an engine.
Another curious question: why does C # not support private (as well as secure) inheritance?
You have a box in your basement. You have never invested anything in this. Someone asks you: "Why is this box empty?" What answer can you give, except that the box is empty, because no one puts anything into it?
C # does not support private or secure inheritance, because no one has ever implemented this feature and sent it to clients. Functions are not performed by default, for free. It's not like we started C # with private and secure inheritance, and then pulled them out for some good reason. These features have never been in the first place, and, unsurprisingly, they are still missing. Features do not grow.
Does multiple inheritance of the implementation support a valid reason, or any other?
I do not understand the question.
Is private (and secure) inheritance planned for future versions of C #?
No.
Will support for private (and secure) inheritance in C # make it a better language than it is now?
I do not think so.
One of the many problems with inheritance that we usually see in OOP is that it fully combines the “peculiar” semantic connection with the “repeated implementation details” of the mechanism relationship. Private inheritance partially eliminates this problem.
There are a small number of situations in which I really enjoyed having private inheritance in C #; a recent example was that I had a data structure that could be built at all, but which I did not want to show to users:
internal class FancyDataStructure<T> {...}
but it is only possible to serialize when T was int (for reasons not related to the discussion). I would like to say:
public class SerializableThingy : private FancyDataStructure<int>
Instead, I simply made a FancyDataStructure<T> nested type SerializableThingy and used composition rather than inheritance. There was a small amount of plumbing code for the record, but it worked out just fine.
I don't think adding a feature pays for itself; this adds to the complexity of the language in exchange for a very small advantage of avoiding some trivial water taxes.
Will support for private (and secure) inheritance in C # make it a more widely used language than it is now?
How could I or did anyone else possibly know the answer to this question? StackOverflow is a poor place to ask questions that require counterfactual forecasting of the future. My suggestions:
- Deploy the C # version with the required function. See if it will become popular. Then you will find out.
- Find a person with psychic abilities who can predict what the future will be like if everything is different now. Since counterfactual predictions automatically follow the rules of deductive logic, predictions will be accurate.