protected ifstream member

I am close to completion of my first OOP project, coming from a C background. I was wondering a design issue related to some ifstream object that I use in the base class to open a file. After that I would like to use the same stream to do further operation by the derived classes. I defined only this member as a protected one so I could reach that in the derived classes, protected breaks the encapsulation(I would like to earn good habits), should I define some getter function to return a reference to a stream object? Since the ifstream objects are not copiable, that might be a problem, first thing I see...

Best, Umut

Answers


protected is ideal for preserving encapsulation, if it's integral to your design that the derived classes have the same I/O functionality as the base class.

Encapsulation does not mean everything has to be private, it means that each data or code member of a given class is visible only to the minimal set of class users to achieve the class's designed purpose. In other words, don't make everything public just because that makes it easier to code.

You would only need a public getter if you wanted to expose the I/O function of the base and derived classes to code outside of the hierarchy. Returning a reference does not imply any copy, by the way.


Need Your Help

Best encryption library for mobile devices?

c++ iphone c android encryption

Hello I have been using LibTomCrypt to use SHA1 encryption ( for data integrity checking ) on mobile devices (iPhone OS and Android for the moment ). I was wondering if anyone is using anything else,

how can i add arabic language with php

php html

i want to create an interface of website in Arabic language....how can i do that...do i need any plugin to be already installed on my hosting server or mylocalhost how can i do that...please let me...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.