C++ and object-oriented programming: encapsulation

Encapsulation is a well known term for software developers, but there is an important bit that is often ignored. Encapsulation hide some variables and methods in two ways, depending on the language. It is done on object or class level.

Encapsulation on object level prevent from using private methods and variables of one object in another object. This approach presents in Java.

Class level mean that the private members can not be accessed from objects of others classes. However, if there are two objects of the same class, they can access their private members each other. In this way encapsulation works in C++.

Example:
[code lang="c++"]
#include
#include
//
using namespace std;
//
class person {
private:
string secret_value;
public:
person( string item ):secret_value(item) { }
void steal( person &victim)
{
cout < < "steal: " << victim.secret_value << "\n";
}
};
//
int main()
{
person men("wallet"), thief("nothing special");
cout << "Thief try to get secret value.\n";
thief.steal( men );
return 0; //that program compiles and works
}
[/code]

Of course I have assumed in above descriptions that there were not any “friends”. A friend of an object can always use its private members.

That was my first article (and hopefully not last) on c++/object-oriented programming/design patterns. I hope you learn something new.

Discussion Join the discussion (0 comments)

First application published

I decided that I will publish some of my projects. The first app is a simple one. Its main task is to test, if packaging to different platforms works. Some files are big, because I included libraries in them.

Screenshot of fire simulation

This app is written in C++ using Qt 4 library. I’m not sure if I use painting in a right way. Profiler shows that app is spending most of the time in drawing functions. I’m wondering if it’s possible to draw on screen more effective using the same library. Unfortunately, I can’t find a document or tutorial that describe this issue.

Discussion Join the discussion (0 comments)

After science camp in Miedzieszyn

Last Saturday (6 May 2006) I returned from a two-week science camp in Miedzieszyn (near Warsaw, Poland). It was organized by KFnrD. There were plenty of various activities. Activities such as workshops and lectures were chooseable and concerned on specific area. There were also evening talks where all participants were welcomed.

The list of all activities that I participate in:

  • Workshops:
    they consist of many lectures, exercises and usually project.
    1. Operating Systems
      A series of following topics: computers architecture, linux kernel internals, file system architecture, debugging and profiling, real time systems, task schedule…
      Exercises such as writing simple modules to linux’s kernel, optimizing programs (mainly memory use), “playing with” user mode linux …
      Project work: write an extension to linux kernel (module, or simply add code) that will collect information about files, blocks, inodes read at boot time. Then use this information to put it all those files together in order they were used. This should reduce time needed to boot.
      Status of project: This project was a bit hard. We try to collect all information, but at last our “best” working solution was getting informations from translation dentry to inode. My strange idea was to create user space program which use inotify and place it in initrd. This solution could work but have two major drawbacks. Firstly, it get info only about whole files, nothing about blocks. Secondly, what’s more important, it’s impossible to use recursive inotify (unlike old dnotify) and it’s hard to put watch on every directory.
    2. Design Patterns
      We learned about various aspects of object-oriented programming and design models and patterns. I will describe them later on this blog.
      Exercises: design architecture for given application.
  • Lectures:
    plus questions, consultations and discussion. All in one event.
    1. What promise quantum informatics? (prof. Marek Ku?, physics)
    2. Poland way to Euro (prof. El?bieta Kawecka-Wyrzykowsk, economics)
    3. Metric holomorphical invariant (PhD Armen Edigarian, mathematics)
    4. Singularities of functions and mappings (prof. Stanis?aw Janeczko, mathematics)
    5. Randomness and order (prof. Tomasz ?uczak, mathematics)
    6. Physics of whip sound (prof. Piotr Piera?ski, physics)
    7. Bernoulli Lemniscate (prof. Marek Bo?ejko, mathematics)
    8. About a few algorithm problems (prof. Wojciech Rytter, informatics)
    9. Difficult theorem about curves on plane (PhD Adrian Langer, mathematics)
  • Others: formal talks (by a scientist, poet or professor etc.),
    there was a lot of them (I was on about 15). They were usually short (< 1.5h) and require only general knowledge. Interesting, but I don’t learned a lot from them.
    Some famous speakers:
    • prof. Jan Madey
    • prof. Pawe? Wieczerzak
    • poet Julia Hartwig
    • director and prof. Krzysztof Zanussi
    • prof. Andrzej S?kowski
    • writer Antoni Libera

What’s more, in Miedzieszyn there is loads of opportunities to share ideas. Strange conceptions like version file system or peer2peer file system occurres ;-). It is also good place to exchange knowledge. For example a person next to you is writing new os from scratch (for education reason only). Now it only boot, handle with memory and support a few posix functions.

From the time I arrived I’m reading KDE/Qt docs, doing simply apps to be prepared for Google Summer of Code. I will desceibe some things that I worked out. I’m also busy at school, despite many lessons were canceled because of the final exams. My CAE exams will also be soon.

Discussion Join the discussion (0 comments)

I go to Miedzieszyn

I’m going to Miedzieszyn for science camp. To anyone from my class: My proposal for a class trip is here. If anything is unclear phone me, as I might not have access to emails.

Discussion Join the discussion (0 comments)