c++ - Questions of google style guide on interface class -
i beginner of c++ , read google style guide. suggests followings interface class.
- it has public pure
virtual("= 0")methods - it may not have
non-staticdata members.
i know reasons why suggests
- (a) interface class should not have default function ,
- (b) non-static data member? question (b), related initialization of class or serialization?
and more trivial , personal question,
- (c) if call "
mix-in" class "protocol" class personally, think of problems? try name mix-in classes marking name, "interface" in "classinterface", suggested google style guide. "mix-in" class not intuitive me although show respects name. "protocol" intuitive me because kind of processes shared players.
if knows reasons or has opinions. please let me know them. thank much.
i'm not sure mean not having default functions. not having data members avoid various kinds of conflicts class has multiple interfaces, or interfaces , true base class.
for example, class x implements interfacea, has member m_foo. if interfaceb has member m_foo, , x decides inherit interfaceb , implement interface, it's existing implementation of x broken, referring m_foo in x ambiguous. see: c++ multiple parents same variable name
i should add: not having member variables logical consequence of interfaces not providing implementation. since don't work or run code, there's no reason interface class need non-static member variables.
edit: ok, defaulted functions, think mean, why style guide functions cannot have implementation , must pure virtual.
it again boils down difficult cases in what's called multiple inheritance in c++. if interface class methods had implementations, inherit them without re implementing. if have 2 interfaces same method name , inherit both, function gets called? it's same problem member variables.
basically, comes fact multiple inheritance in c++ can quite tricky. rules interfaces mimic actual language construct in java, not have full multiple inheritance. these restrictions, can avoid these tricky situations, lose of power of c++ full multiple inheritance.
Comments
Post a Comment