Archiv des Autors: oliverfunke

Prefer non-member functions

In C++ you can write a function as member function of a class or as non-member function outside of classes. But which of this both software designs is applicable? Which one do you should prefer? The answer is easy: It … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

Returning handles to private members makes them public

Some key features of object-oriented programming can be brunch together to something I want to call the “black box idea”. An object is a black box offering a public interface. All internal implementations, like state management, data control and resource … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

Design patterns: Command

The Command design pattern encapsulates a request as an object. This will allow adding additional functionality to the request. A typical example is the undo/redo functionality. The command object will be used as mediator between the client and the receiver … Weiterlesen

Veröffentlicht unter .NET, C#, Design Pattern | Kommentar hinterlassen

Define a variable inside or outside of a loop

If you implement something you will write a lot of loops. Within the loops you will often use variables. This is a very common issue but it isn’t that easy like it looks in the first moment. Because you have … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

Slicing problem

By default C++ will pass parameters by value. Therefore when you pass an object to a method a copy of this object will be created. Other languages, for example C# will pass parameters by implicit references. If you work with … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

Methods should do one thing only

According to the Single Responsibility Principle a class should have one, and only one, reason to change. To same statement is valid for methods. A method should do one thing only and therefore have only one reason to change. Unfortunately … Weiterlesen

Veröffentlicht unter .NET, C#, Clean Code | Kommentar hinterlassen

Manage resources by using smart pointer RAII objects

A common way to create objects is by using a factory method or an abstract factory. Such a factory will normally create and return the object and handover the responsibility over the object to the client. Therefore the client has … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen