Author image

Composite Design Pattern


Join me in our quest to decipher the obscure Composite software design Pattern hieroglyphics.

Definition: Compose objects into tree structures to represent part-whole hierarchies.

The Composite pattern is a structural pattern which enables us to iterate over objects, or collection of those objects in a uniform manner, without having to typecheck or differentiate between the concrete objects and their collections. All those objects share a common interface, an abstract base class.

The whole point of the Composite pattern is that the Composite can be treated atomically as if it was a leaf object, without needing to know that there are many objects inside. Leaf objects perform a request directly, and Composite objects forward the request to their child components recursively downwards the tree...

Author image

Proxy Design Pattern


What is a proxy? Dictionary says “The authority to represent someone else”. hmmm… Ponder on that a bit and let's see how the “Name and Conquer” of Proxy applies to software design patterns.

The definition of the Proxy pattern goes like this:

Provides a surrogate or placeholder for another object in order to control access to it.

Let's get the obvious stuff out of the way:

  1. A proxy certainly provides another level of indirection to another “target” object that we basically want to access

That's it. I have nothing else that seems obvious from the definition alone. But after further investigation and coding I realize that a Proxy object is indeed useful when we want to lazy-instantiate an object, or when we want to hide the implementation details of the object. For whatever reason, but this often comes up in software, we represent a back-end highly complicated object with a more...

Author image

Adapter/Wrapper/Facade Design Pattern


Here we will disambiguate the Adapter Wrapper Facade Software Design patterns.

A confused pattern, yes.
It has many names.
Adapter, Facade, Wrapper.
But they're all pretty much the same..

The Adapter (aka Facade aka Wrapper class) wraps a legacy class with a new interface into an updated class that respects the new interface.

It is most often used to make existing classes work with others (perhaps new ones) without modifying their source code. Many Windows WinAPI functions are an example of this.

Design

  • an interface (perhaps legacy) is not compatible with the current system needs
  • an abstract base class is created that specifies the desired interface
  • an adapter class is defined that publicly inherits the interface of the abstract class, and privately inherits the implementation of the legacy class
  • this adapter class “(impedance) matches”...

Author image

Pointer to Implementation (Pimpl) - Bridge Design Pattern


In the non-C++ world Pimpl is otherwise known as the Bridge design pattern, with the following definition:

Decouple an abstraction from its implementation so that the two can be extended independently.

In the vain of Bridge, in C++, when anything in a header file class definition changes, all users of that class must be recompiled - even if the only change was to the private class members that the users/clients of the class cannot even access. This is because C++'s build model is based on textual inclusion, and because C++ assumes that callers know two main things about a class that can be affected by private members: 1. Size and Layout 2. Functions

Because private data members of a class participate in its object representation, affecting size and layout, and because private member functions of a class participate in overload resolution (which takes place before member access checking), any change to those implementation...

Author image

Prototype Design Pattern


Implementing Prototype Design Pattern like a boss and then laughing it off.
Bonus: coool way of spawning arrays of objects from a prototypical instance (check spawnMonsterArray).

The prototype pattern is a creational software design pattern, that is used when the type of object(s) to create is determined by a prototypical instance, which is cloned to produce new objects. This pattern is used to:

  • avoid subclasses of an object creator, like the factory pattern does
  • avoid the inherent cost of creating a new object in the standard way (like using new) when it can be prohibitively expensive for a given application

Design

  • define an abstract Prototype class with a clone() method that returns a copy of itself
  • create subclasses of Prototype . These will...

Author image

Builder Design Pattern


An introduction to the Builder software design pattern along with a fancy example, which will make you go from Zero-to-Hero in no time on becoming a master Bob the Builder!

The Builder pattern is designed to provide a flexible solution to various object creation problems in OOP. We intend to separate the construction of a complex object from its representation.

Advantages

It provides control over the individual steps in the object construction process such that we can better customize object representation. This benefit really shine when we have big complicated classes.

Disadvantages

It requires a separate Builder class for each type of such complex object and it makes dependency injection harder to work with since introducing many dependencies can get things out of hand.

Also it increases code size and almost doubles the amount of memory required since almost all variables...

Author image

Factory Design Pattern


Definition:

Define an interface for creating an object, but let subclasses decide which class to instantiate.

Description

The factory function is used to create an object of any type of subclass of a base class.
Instead of creating objects like this:

ObjectType* o = new SubObjectType{args};

we create them like this:

ObjectType* o = newSubObjectType{args};

Where newSubObjectType is the factory function's name. Yes, the factory is nothing more but a construction function for objects; it's typically a global/free function (not a method).

You might wonder, what is the usefulness of this design pattern?

Well, that's a legitimate question. I use the Factory pattern, when all the potential classes I'd like to create are in the same subclass hierarchy, but...

Author image

Alien Space Battle - Space Invaders lookalike Game


Want to get familiar with Python Pygame library (like I did)? Then check this "2d Space Invaders game clone" out! Pygame hides many of the down and dirty implementation details and all you're basically left to do is create the game logic. If you want to do something similar this project will surely help you.

Author image

Memory Allocators Galore

Allocators are strange creatures in the C++ bestiary, but they are key to understanding the language internals. Are you fascinated by memory allocation in the lower level? Well you've come to the right place!

This projects encompasses my efforts around creating some of the most popular memory allocators and it will serve as a reference point henceforth:

  1. Pre-C++11 default allocator (DefaultAllocator & TrackingAllocator projects)
  2. C++11 compatible allocator replacements (Allocators & AlignedAllocator projects)
  3. Linear (aka Arena) allocator (LinearAllocatorproject)
  4. Stack Allocator (StackAllocator &...

Author image

Buffer Overflow Tutorial


This is a Buffer overflow tutorial using linux Ubuntu and C programming. There is full explanation and code in Greek only at the moment in “Nikos_Lazaridis_M1485_Project#2_ΥΣ13_ΕΑΡΙΝΟ_2017.pdf”. I may be motivated to translate this in English if I see any traffic.

! During Buffer Overflow:
The ultimate goal of a Buffer overflow attack is replacing the return address of a vulnerable/unsecure function with another one of our choosing. The latter function will have "ASCII shellcode" placed into it, which will execute the attacker's desired code (WE are the attacker here); the sky's the limit with what the attacker can do (more like the imagination of the attacker). “Buffer Overflow” occurs the moment where a single byte is written in the return address...

1 2 3 4 ... 6