Skip to content

jdgarciauc3m/polyexamples

Repository files navigation

polyexamples

This repo contains examples of different approaches of polymorphism with a very simple example. The example is writing programs for reading, writing, and performing computations on an scene composed by a number of figures.

Included solutions

The different directories contain:

  • shape: A simple solution with an scene as a collection of rectangles.
  • shapegen: The scene is templated so that a scene may be a collection of rectangles or a collection of circles, but not both.
  • shapeoo: Classical Object Oriented solution. Rectangles and circles are part of a hierarchy (with shape as base class) and a scene is a collection of pointers to shapes.
  • shape-type-erased: Highly inspired by Sean Parent's talk (inheritance is base class of evil). Rectangle and circle are independent classes with no common base. Shape class provides value semantics and a scene contains a collection of shapes.
  • shape-small-object: An evolution of previous one with the addition of small object optimization.
  • shapehgenopt: Small object optimization with aligned buffer. Note that vector of shapes is however not aligned.

How to compile and run

Each directory contains their corresponding Cmake files.

For each directory:

  1. Enter the corresponding directory.
  2. Create a new directory named build.
  3. cd build
  4. cmake ..
  5. make

Remember that you can cmake ..to edit compiler options. In particular do not forget that for performance comparisons is important to set the Release build mode.

If you want to run your own performance measurements, you can make use of simple shell scripts under directory scripts.

Contact

If you have any issue with the code, please contact me at josedaniel.garcia@uc3m.es.

About

Examples of polymorphism approaches

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published