Given the following code:
class BaseClass
{
    protected void Do(var param) {}; 
}
class DerivedClass
{
     public开发者_Go百科 void DoSomething()
     {
        var param = something;
        Do(param);
     }
}
Is this the proper way to use inheritance? I would think I would have put the "Do" method in a separate class and use composition. However, that would violate encapsulation, as I would have to acces an object in the base class:
class DerivedClass
{
   public void DoSomething()
   {
      var param = something;
      base.GetObject().Do(param); 
   }
}
Yep that way if good =] Composition here probably wouldn't break encapsulation, but this seems like an acceptable use of inehritance.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论