Tuesday, July 3, 2012

Back to Basics - Bitwise Flags


Recently I was using a question about managing a parking garage in an Object Oriented course I'm teaching and in job interviews for a position I was recruiting.

The question asks to manage a parking garage where each customer can submit requirements when getting in, for specific parking place attributes (such as "shaded", "not blocked", "tall vehicle" etc.) and for consuming services while parking (such as "car wash", "electric charging" etc.)

The garage has of course parking places which support these requirements or some of them and able to provide the required services in some of the parking places.

The question was to model and implement the management system for the garage, so customer requirements can be answered by pointing the car to the relevant free place or replying the customer that no free place satisfies the requirements.

Has one can understand from the title of this post, it is more than reasonable to think of bitwise flags here. However, the Object Oriented thinking might work here extra hours and lead to unnecessary classes, or even worse, horrible class hierarchies.

The beauty of bitwise flags is that matching can be done based on simple bitwise operations.

What do require some Object Oriented thinking is managing the price tariffs for the garage!