AUTOSAR C++14 Rule A10-4-1
Description
Rule Definition
Hierarchies should be based on interface classes.
Rationale
An interface class has these properties:
- If the class has member functions, they are public and pure - virtual.
- If the class has data members, they are public and - static constexpr.
Using an interface class as a base class in a hierarchy:
- Separates the interface and implementation. The code of the base class is more stable and easier to maintain. 
- Avoids unnecessary computations of nonstatic data members in the derived classes and other compilation dependencies. 
- Makes your software easier to extend and enables the use of alternative implementations through the same interface. 
Polyspace Implementation
Polyspace® flags the base of a class hierarchy if that base class is not an interface.
When class definitions are nested in other classes, the checker follows these conventions:
- Non-interface base classes are flagged even if the hierarchy is nested inside another class. For example, in this code snippet, class - NestedBaseis flagged :- class ClassWithNestedHierarchy { class NestedBase //Non-compliant, not an interface { public: int i; }; class NestedDerived : public NestedBase { public: int j; }; };
- Base classes with nested non-interface classes are not flagged. For example, in this code snippet, - NestedClassis not an interface class but the outer class- InterfaceWithInnerClassis not flagged when used as a base class:- class InterfaceWithInnerClass { public: class NestedClass //not an interface class { private: int i; }; static constexpr NestedClass i{}; }; class DerivedBaseWithInnerClass : public InterfaceWithInnerClass { private: int i; };
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
| Group: Derived Classes | 
| Category: Advisory, Non-automated | 
Version History
Introduced in R2021b