I have been reading through the C++ FAQ and was curious about the friend declaration. I personally have never used it, however I am interested in exploring the language.
What is a good example of using friend?
Edit:
Reading the FAQ a bit longer I like the idea of the << >> operator overloading and adding as a friend of those classes....
Can you tell me what is difference between ABSTRACTION and INFORMATION HIDING in software development?
I am confused abstraction hides detail implementation and
information hiding abstracts whole details of something.
updated:
I found good answer for these three concepts.
From here: http://www.itmweb.com/essay550.htm
Abstraction: ...
Is there something like the Python descriptor protocol implemented in other languages? It seems like a nice way to increase modularity/encapsulation without bloating your containing class' implementation, but I've never heard of a similar thing in any other languages. Is it likely absent from other languages because of the lookup overhea...
Python gives us the ability to create 'private' methods and variables within a class by prepending double underscores to the name, like so: *__myPrivateMethod()*. How, then, can one explain this
>>> class MyClass:
... def myPublicMethod(self):
... print 'public method'
... def __myPrivateMethod(self):
... ...
One of the biggest advantages of object-oriented programming is encapsulation, and one of the "truths" we've (or, at least, I've) been taught is that members should always be made private and made available via accessor and mutator methods, thus ensuring the ability to verify and validate the changes.
I'm curious, though, how important ...
class MyContainedClass {
};
class MyClass {
public:
MyContainedClass * getElement() {
// ...
std::list<MyContainedClass>::iterator it = ... // retrieve somehow
return &(*it);
}
// other methods
private:
std::list<MyContainedClass> m_contained;
};
Though msdn says std::list should not perform relocations of elements...
Hello world!
I have been using C# for a while now, and going back to C++ is a headache. I am trying to get some of my practices from C# with me to C++, but I am finding some resistance and I would be glad to accept your help.
I would like to expose an iterator for a class like this:
template <class T>
class MyContainer
{
public:
/...
One of the really nice things about python is the simplicity with which you can name variables that have the same name as the accessor:
self.__value = 1
def value():
return self.__value
Is there a simple way of providing access to the private members of a class that I wish to subclass? Often I wish to simply work with the raw dat...
I've been working with the Joomla framework and I have noticed that they use a convention to designate private or protected methods (they put an underscore "_" in front of the method name), but they do not explicitly declare any methods public, private, or protected. Why is this? Does it have to do with portability? Are the public, pr...
what is the best way to put a container class or a some other class inside a class as private or a public member?
Requirements:
1.Vector< someclass> inside my class
2.Add and count of vector is needed interface
...
As you may already know, the .NET Framework's protected internal access modifier works in a strange way: It doesn't mean the class is protected AND internal, it says the class is protected OR internal; that is, the modified class or member can be accessed from whitin the same assembly as well as from the same hierarchy.
So, knowing this...
I sometimes have difficulties with other people who wish to solve a problem when they wish to skip the official interfaces and access underlying implementation details directly.
They argue that doing so will allow them to solve the problem more quickly. I argue that doing so will cause our architecture to become more tightly coupled an...
I used to have a custom preferences class for my applications. For my next hobby project i wanted to switch to the Preferences API. But the put and get functions require a default value and i do not want to spread default values all over the source files. Even though my project is small i can not imagine changing default values all over ...
Hi all,
I am dabbling in the world of web services and I've been making a simple web service which mimics mathematical operations. Firstly it was simple, passing in two integers and then a binary operator would be applied to these (plus, minus etc) depending on the method called.
Then I decided to make things a little more complex and ...
I have some event handler on a boundary class that manages a persistence mechanism for a given generic transaction:
void MyBoundaryClass::MyEventHandler(...)
{
//retrieve stuff from the UI
//...
//declare and initialize trasaction to persist
SimpleTransaction myTransaction(.../*pass down stuff*/);
//do some other checks
//.....
In OOP languages like C# or VB.NET, if I make the properties or functions in a super class protected I can't access then in my Form, They can only be access in my class that inherits from that super class.
To access those properties or functions I need to make them public which defeats encapsulation on re-write them in my class which de...
There's some object-oriented engineering principle that states something along the lines of "a class should only know about the contracts of the classes that it takes as arguments, or any internal ones it uses."
The counter-example, in C++, is:
Foo::bar( Baz* baz)
{
baz()->blargh()->pants()->soil(); // this is bad, Foo knows about b...
This question came from the worst interview questions thread here
So, what are the different types of encapsulation?
Am I right in thinking this basically refers to central OO concepts such as Abstraction, Polymorphism and Inheritance?
My understanding of encapsulation is that it is a method of hiding data / functionality, but I never...
I am sick and tired of getting yelled at when I make all my variables in a Java class public, for the sake of not needing to write five times more code for getters and setters.
Do others share this problem?
...
How can I create a method in the @implementation of a class without defining it in the @interface?
For example, I have a constructor that does some initialisation and then reads data from a file. I want to factor out the file-reading code into a separate method that I then call from within the constructor. I don't want to define this ...