Tuesday 15 March 2011

c++ - Is it OK for an abstract base class have non-abstract methods? -


In an abstract base class (interface class) it usually has all its function summary. However, I have many such issues Where the member who calls the intangible methods of the interface works. I can apply them to a derivative-only-still intangible class, or I can implement methods in the form of non-abstract, non-virtual methods of the interface class.

Is any problem implemented according to the design design in the interface class?

For example

  class IFoo {Public: Is this a bad style, and if so, why?  

Virtual ~ IFoo (); Virtual Double Calc (InputType p) const = 0; Virtual Double CalThat (Input Type P) const = 0; Double calcefructure (Inup type P) {calce it (P) / calcite (P); } Fixed BarType Bar (InputType p); }; Class MyFoo: Public IFoo {Public: // IFoo virtual double calc it (InputType p) const; // IFoo virtual double calceat (InputType p) const applies; };

vs

  class IFoo {public: virtual ~ IFoo (); Virtual Double Calc (InputType p) const = 0; Virtual Double CalThat (Input Type P) const = 0; }; Class FooBase: Public IFoo {Public: Virtual ~ FooBase (); Double calcefructure (Inup type P) {calce it (P) / calcite (P); } Fixed BarType Bar (InputType p); }; Class MyFoo: Public Phobbs {Public: // IFoo Virtual Double Calc It (Input Type P) CONST; // IFoo virtual double calceat (InputType p) const applies; };  

if you call it an interface (i.e.) Which you seem to be using your naming convention "IFU"), then it should not be a pure interface (no implementation).

If this is only an abstract class, then the combination of pure virtual and implemented methods is absolutely reasonable.


No comments:

Post a Comment