c++ - protected ifstream member -
i close completion of first oop project, coming c background. wondering design issue related ifstream object use in base class open file. after use same stream further operation derived classes. defined member protected 1 reach in derived classes, protected breaks encapsulation(i earn habits), should define getter function return reference stream object? since ifstream objects not copiable, might problem, first thing see...
best, umut
protected ideal preserving encapsulation, if it's integral design derived classes have same i/o functionality base class.
encapsulation not mean has private, means each data or code member of given class visible minimal set of class users achieve class's designed purpose. in other words, don't make public because makes easier code.
you need public getter if wanted expose i/o function of base , derived classes code outside of hierarchy. returning reference not imply copy, way.
Comments
Post a Comment