The Decorator Pattern

The decorator pattern is one of the classic structural patterns. A decorator wraps an existing object and provides additional functionality (decoration) whilst providing the same interface as the original object. One example which comes to mind is from an episode of Flight of the Conchords. Bret tries to ‘upgrade’ an ordinary mobile phone by gluing … Read more

The Builder Pattern

In this post we will discuss the Builder Pattern. This is one of the standard creational design patterns. It is particularly relevant when dealing with complex objects which may be conceptually built up from a set of components. In this pattern, the object is often built up in stages rather than being created immediately in … Read more

Quaternions part 2

In the previous post, we introduced quaternions and discussed some of their basic properties. Quaternions are often used in 3D applications such as graphics and robotics to perform smooth rotations. In this post we describe how to use quaternions to represent points in 3D and how to use quaternion operations to perform rotations about an … Read more

Quaternions

Quaternions define a 4 dimensional algebra which is particularly useful for dealing with rotations in 3d. They are often used when you might want to produce a smooth rotation by interpolating between two orientations. Common applications are 3d graphics animation (e.g. games or CGI) and robotic kinematics. Quaternions can be thought of as being similar … Read more

Scoped Enumerations

In C++03, enumerations are declared as follows: enum Suit { Hearts, Diamonds, Clubs, Spades }; Suit suit = Hearts; As can be seen, Hearts is in the global namespace. This could give rise to potential name collisions with other enums. Another issue is that it is difficult to find instances of a particular enum via … Read more

Overriding Functions

The C++03 way In C++03, the virtual keyword is used to implement function overloading, as shown in the example below: class Shape { public: virtual bool isCircle() { return false; } }; class Circle : public Shape { virtual bool isCircle() { return true; } }; We can test this code as follows: bool test() … Read more