Está en la página 1de 42

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

8. Object-oriented Programming June 15, 2010

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 1 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Outline

Recapitulation Copy Constructor & Operators Object-oriented Programming Dynamic and Static Polymorphism The Keyword Static The Singleton Pattern Generic Programming

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 2 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

8.1. Brain Teaser


class String { private : / / a i n t a 0 t e r m i n a t e d s t r i n g char d a t a ; / / length of s t r i n g int length ; public : String ( ) ; v o i d copyFromOtherString ( c o n s t S t r i n g & s t r i n g ) ; }; ... String : : String ( ) : data ( 0 ) , l e n g t h ( 0 ) {} v o i d S t r i n g : : copyFromOtherString ( c o n s t S t r i n g & s t r i n g ) { data = s t r i n g . data ; length = string . length ; s }

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 3 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

8.2. Copy Constructor and Operators


C++ generates a couple of default operations for any class/struct to allow you to

use these datatypes as you use a built-in datatype.


int a(10); Date myDate ( anotherDate ) ;

Sometimes, we have to rewrite these default operations. For the copy constructor, it is very simple.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 4 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Copy Constructor for a String Class


class String { private : / / a i n t a 0 t e r m i n a t e d s t r i n g char d a t a ; / / length of s t r i n g int length ; public : String ( ) ; S t r i n g ( const S t r i n g& s t r i n g ) ; }; ... String : : String ( ) : data ( 0 ) , l e n g t h ( 0 ) {} S t r i n g : : S t r i n g ( const S t r i n g& s t r i n g ) : data ( 0 ) , length ( string . length ) { d a t a = new . . . ; for ( . . . ) { ... } }
8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 5 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Excursus: C++ Strings


Good news: You now know how to write a copy constructor for your personal string

class.
Bad news: Such a class does already exist. # i n c l u d e <s t r i n g > s t d : : s t r i n g myString0 ; s t d : : s t r i n g myString1 ( h e l l o w o r l d ) ; s t d : : s t r i n g myString2 ( myString1 ) ; s t d : : s t r i n g myString3 = h e l l o MPG ; s t d : : s t r i n g myString4 = myString3 ; myString . l e n g t h ( ) ; myString4 += myString1 ;

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 6 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Default Operations
The following operations are generated automatically as public operations if we

dont provide our own implementation: Default constructor. Destructor. Copy constructor.
However, theres still another pitfall: MyString a ; / / do something w i t h a ; MyString b ( a ) ; / / works MyString c ; c = a; / / does n o t work

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 7 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Operators
In C++, operators such as +,-,+=,=, are just methods, too. The = operators (assignment operator) is generates automatically, if we dont

overwrite it.
It then is a bit-wise copy of the object. We can redene the operators. We now know, what std : : cout < < stupid < < std : : endl

means.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 8 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Operators RedenedPart I
class Vector { public : / / copy c o n s t r u c t o r V e c t o r ( c o n s t V e c t o r& v e c t o r ) ; V e c t o r& o p e r a t o r =( c o n s t V e c t o r& v e c t o r ) ; / / unary o p e r a t o r s V e c t o r& o p e r a t o r +=( c o n s t V e c t o r& v e c t o r ) ; V e c t o r& o p e r a t o r =( c o n s t double& v a l u e ) ; v o i d toStream ( s t d : : ostream& o u t ) c o n s t ; }; / / binary operators V e c t o r& o p e r a t o r +( c o n s t V e c t o r& l h s , c o n s t V e c t o r& r h s ) ; s t d : : ostream& o p e r a t o r <<(s t d : : ostream& out , c o n s t V e c t o r& v e c t o r ) ; ... V e c t o r& o p e r a t o r +( c o n s t V e c t o r& l h s , c o n s t V e c t o r& r h s ) { Vector r e s u l t ( lhs ) ; r e s u l t += r h s ; return result ; }

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 9 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Operators RedenedPart II
class Vector { public : / / copy c o n s t r u c t o r V e c t o r ( c o n s t V e c t o r& v e c t o r ) ; V e c t o r& o p e r a t o r =( c o n s t V e c t o r& v e c t o r ) ; / / unary o p e r a t o r s V e c t o r& o p e r a t o r +=( c o n s t V e c t o r& v e c t o r ) ; V e c t o r& o p e r a t o r =( c o n s t double& v a l u e ) ; v o i d toStream ( s t d : : ostream& o u t ) c o n s t ; }; / / binary operators V e c t o r& o p e r a t o r +( c o n s t V e c t o r& l h s , c o n s t V e c t o r& r h s ) ; s t d : : ostream& o p e r a t o r <<(s t d : : ostream& out , c o n s t V e c t o r& v e c t o r ) ; ... s t d : : ostream& o p e r a t o r <<(s t d : : ostream& out , c o n s t V e c t o r& v e c t o r ) { v e c t o r . toStream ( o u t ) ; r e t u r n out ; }

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 10 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

8.3. Inheritance
Sometimes, someone hands you over an object, but this object lacks some

functionality.
Now, it is up to you to add this functionality. However, what happens if there is different variants of this functionality? Image you write a researcher management application. Let Employee be a multi-purpose class for bookkeeping. Task: Add a function setSalary () and getTaxesPaid . However: There are also people getting a stipend. These guys do not pay taxes. Writing two classes is not a variant, as all employees have to have a getWeight()

operation. Challenge: If we duplicate the code, then multiple operations have to be rewritten:
b o o l isBMIAboveThreshold ( ) { ... }

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 11 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Challenge Rewritten

A Stipend is an extension of Employee. A PostDoc is an extension of Employee, too. Stipdend and PostDoc are two different things. Whatever we do with an Employee, we can do with a Stipend and PostDoc, too.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 12 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

is aRelations
AbstractDB getEntry()

RealDatabase

HardcodedTestDB

Student has all operations and attributes, Employee has. Every operation expecting an instance of Employee could also be passed an

instance of Student.
Again, we could image this to be an extension of a cut-n-paste mechanism.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 13 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

is aRelations in Source Code (Part I)


c l a s s Employee { private : double w e i g h t ; ; public : b o o l isBMIAboveThreshold ( ) ; }; c l a s s S t i p e n d : p u b l i c Employee { private : public : double g e t S t i p d e n d ( ) c o n s t ; }; ... S t i p e n d myStipend ; myStipend . isBMIAboveThreshold ( ) ;

/ / that s fine

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 14 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

is aRelations in Source Code (Part II)


c l a s s Employee { ... }; c l a s s S t i p e n d : p u b l i c Employee { ... }; v o i d f o o ( c o n s t Employee& employee ) { . . . } S t i p e n d myStipend ; f o o ( myStipend ) ;

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 15 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Object-oriented Programming
is-a relations are mapped to inheritance. Object-based programming becomes object-oriented programming due to this

inheritance concept.
Whenever an object of type A is expected somewhere, we can also pass an object

with a subtype of B . This concept is called polymorphism.


Theres a new visibility mode protected: These attributes and operations behave

like private, i.e. they are not visible from outside, but they are visible within subclasses.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 16 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

8.4. virtual Operations


class A { public : void foo ( ) ; }; class B: public A { public : void foo ( ) ; }; c l a s s C: p u b l i c B { public : void foo ( ) ; }; A B C A A B object1 ; object2 ; object3 ; o b j e c t 4 = new A ( ) ; o b j e c t 5 = new B ( ) ; o b j e c t 6 = new C ( ) ;

object1 . foo ( ) ; object2 . foo ( ) ; object3 . foo ( ) ; o b j e c t 4 >f o o ( ) ; o b j e c t 5 >f o o ( ) ; o b j e c t 6 >f o o ( ) ;


8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 17 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Static Polymorphism
class A { public : void foo ( ) ; }; class B: public A { public : void foo ( ) ; }; A o b j e c t 4 = new A ( ) ; o b j e c t 4 >f o o ( ) ;

C++ implements a static polymorphism by default. It is called static, as the (known) object type determines which operation is to be

invoked.
There is a variant called dynamic polymorphism, too. Java, C# support only dynamic polymorphism.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 18 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Dynamic Polymorphism
class A { public : void foo ( ) ; v i r t u a l v o i d bar ( ) ; }; class B: public A { public : void foo ( ) ; v i r t u a l v o i d bar ( ) ; }; A o b j e c t 1 = new A ( ) ; B o b j e c t 2 = new B ( ) ; A o b j e c t 3 = new B ( ) ; o b j e c t 1 >f o o o b j e c t 2 >f o o o b j e c t 3 >f o o o b j e c t 1 >bar o b j e c t 2 >bar o b j e c t 3 >bar (); (); (); (); (); ();

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 19 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Dynamic Destructors

If you use inheritance, always make your destructor virtual.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 20 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Finally: Super Constructor


class A { public : A( i n t v a r i a b l e ) ; }; class B: public A { public : B(); }; ... B::B(): A ( 23 ) { }

This is the reason, C++ introduced initialisation lists, and treats both attributes and super types the same way. Please take care of the order: First, you have to call the supertypes constructor, then you have to initialise your attributes in the right order.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 21 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Excursus: Multiple Inheritance


class A { }; class B { }; c l a s s C: p u b l i c A , B { };

Multiple inheritance is supported by C++. However, today it is considered to be a bad smell. Theres also a concept called virtual inheritance which is also considered to be a

bad smell nowadays.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 22 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Excursus: Private Inheritance


class A { }; class B { }; c l a s s C: p r i v a t e A , B { };

Private inheritance is supported by C++. Here, the is-a relationship does not hold anymore, i.e. it is a pure implementation

inheritance, not a behavioural.


However, today it is considered to be a bad smell. I nevertheless nd is useful.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 23 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Abstract Operations
class A { }; class B: public A { }; c l a s s C: p u b l i c A { };

Let B and C be classes that belong together logically. An example: B writes

measurements into a database, C plots data to Matlab.


However, B and C have to implementation in common. They share solely the

signature.
Consequently, all operations (in A) have to be virtual. However, it does not make sense to provide any default implementation of an

operation in A.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 24 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Abstract Operations
class A { v i r t u a l void foo ( ) = 0; }; class B: public A { v i r t u a l void foo ( ) ; }; c l a s s C: p u b l i c A { v i r t u a l void foo ( ) ; };

vitual operations can be made abstract. A class with at least one abstract method is an abstract class. We cannot instantiate abstract types. This way, we enforce subclasses to implement them. Classes with solely abstract operations are called interface.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 25 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

8.5. static Variable Lifecycle


void foo ( ) { i n t myInt ; ... } v o i d bar ( ) { s t a t i c i n t myInt ; ... }

Variables belong to a scope. Whenever we encounter a variable denition, we reserve memory. At the end of the scope, the variable is destroyed (invoke destructor, free memory).

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 26 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Static Variables
void foo ( ) { i n t myInt ; ... } v o i d bar ( ) { s t a t i c i n t myInt ; ... }

Variables belong to a scope. Whenever we encounter a static variable denition for the rst time, we reserve

memory.
A static variable is freed when the application terminates (invoke destructor, free

memory).

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 27 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

An Example for Static Variables


v o i d bar ( ) { s t a t i c i n t myInt = 2 0 ; myInt ++; } ... bar ( ) ; bar ( ) ; bar ( ) ;

//

first

c a l l o f bar ( ) ever

Static variables are bind to the application, not to the scope. However, they are still accessible only within the scope. Usuall, (good?) procedural programmers do not use static.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 28 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Object Variables
class A { int field ; void foo ( ) ; }; v o i d A : : f o o ( ) { f i e l d ++; } A instance1 , instance2 ; instance1 . foo ( ) ; instance2 . foo ( ) ;

Both instances work on different instantiations of field.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 29 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Class Variables (Static)


class A { static int field ; void foo ( ) ; }; v o i d A : : f o o ( ) { f i e l d ++; } A instance1 , instance2 ; instance1 . foo ( ) ; instance2 . foo ( ) ; A : : f i e l d ++;

Here, static binds the attribute to the class. It is a class attribute. Depending on the visibility, one can either access the static attribute within any operation of A, or even outside of the class (not recommended as it violates the encapsulation idea). If the eld is public, the class acts (from a syntax point of view) similar to a namespace.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 30 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Example: Instance Counter


class A { private : s t a t i c i n t instances ; public : A(); }; void A : : A( ) { i n s t a n c e s ++; }

This code keeps track how many instances of A are created.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 31 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Static Operations
class A { public : void foo ( ) ; s t a t i c v o i d bar ( ) ; }; void A : : foo ( ) { . . . } v o i d A : : bar ( ) { . . . }

We can also declare methods as static. Static methods (class methods) belong to the class, not to an object. Static methods may work on class attributes only.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 32 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

A Factory Method
class A { private : int attribute ; public : s t a t i c A createAnAFromTerminal ( ) ; }; s t a t i c A createAnAFromTerminal ( ) { A result ; std : : cin > > result . attribute ; return A; } ... A myA ; myA = A : : createAnAFromTerminal ( ) ; Static methods may manipulate any attribute of the class as they are part of the

class.
Static methods are called similar to methods wrapped by a namespace. Static methods typically represent operations on sets while methods represent

operations on an element of a set.


8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 33 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

8.6. Design Patterns

Design Patterns: Stem from reocurring

solutions for certain technical challenges.


More complex than idioms. Something different than an algorithm:

It describes the technical realisation.


Famous book by the gang of four.

Standard book by the gang of four.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 34 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

A Singleton
/ Implements a c o n n e c t i o n t o a database ( b i g f i l e ) w i t h l o t s o f material constants . / c l a s s M a t e r i a l C o n s t a n t s {} ;

We want to ensure that MaterialConstants is created only once throughout the application lifecycle. Here are some hints:
MaterialConstants should not have a

public (default) constructor.


As anyone could need the database, a

static getDatabase() operation might be helpful that returns an instance of MaterialConstants.


This static operation might hold an

instance of MaterialConstants. However, it should not create it each time it is invoked.


8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 35 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Singleton Implementation - Part I


class MaterialConstants { private : / noone should be a b l e i n s t a n t i a t e t h e database on h i s own / MaterialConstants ( ) ; / noone should be a b l e t o copy a database / M a t e r i a l C o n s t a n t s ( c o n s t M a t e r i a l C o n s t a n t s & ) ; / / noone should be a b l e public : i n t getEntry ( ) const ; v o i d addEntry ( . . . ) ; };

... M a t e r i a l C o n s t a n t s myDatabase ;

/ / forbidden

/ / however , we need something l i k e myDatabase . g e t E n t r y ( ) ;

We could make all the operations static. However, then we dont have control of the open process. Even worse, this wont t to our fancy new object-oriented paradigm.
8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 36 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Singleton Implementation - Part II


class MaterialConstants { private : / noone should be a b l e i n s t a n t i a t e t h e database on h i s own / MaterialConstants ( ) ; / noone should be a b l e t o copy a database / M a t e r i a l C o n s t a n t s ( c o n s t M a t e r i a l C o n s t a n t s & ) ; / / noone should be a b l e public : ... / P r o v i d e access t o one s i n g l e database ( s i n g l e t o n ) / s t a t i c M a t e r i a l C o n s t a n t s& getDatabase ( ) ; }; ... M a t e r i a l C o n s t a n t s : : getDatabase ( ) . g e t E n t r y ( ) ; M a t e r i a l C o n s t a n t s myConstants = M a t e r i a l C o n s t a n t s : : getDatabase ( ) ;

/ / fine / / forbidden

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 37 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Singleton Implementation - Part III


class MaterialConstants { private : ... public : ... / P r o v i d e access t o one s i n g l e database ( s i n g l e t o n ) / s t a t i c M a t e r i a l C o n s t a n t s& getDatabase ( ) ; }; M a t e r i a l C o n s t a n t s& M a t e r i a l C o n s t a n t s : : getDatabase ( ) { MaterialConstants r e s u l t ; return result ; }

This simple realisation of the static operation works. However, it creates a segmentation fault.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 38 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Singleton Implementation - Part III


class MaterialConstants { private : ... public : ... / P r o v i d e access t o one s i n g l e database ( s i n g l e t o n ) / s t a t i c M a t e r i a l C o n s t a n t s& getDatabase ( ) ; }; M a t e r i a l C o n s t a n t s& M a t e r i a l C o n s t a n t s : : getDatabase ( ) { MaterialConstants r e s u l t ; return result ; }

This simple realisation of the static operation works. However, it creates a segmentation fault. If we removed the reference symbol, it would create one instance and one copy per call. That is not what we want.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 38 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

Singleton Implementation - Part IV


class MaterialConstants { private : ... public : ... / P r o v i d e access t o one s i n g l e database ( s i n g l e t o n ) / s t a t i c M a t e r i a l C o n s t a n t s& getDatabase ( ) ; }; M a t e r i a l C o n s t a n t s& M a t e r i a l C o n s t a n t s : : getDatabase ( ) { s t a t i c MaterialConstants r e s u l t ; return result ; }

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 39 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

A Factory Pattern

Study our simple MaterialConstants

type.
This shall be part of a project where

we are promised to get access to the real database by the end of the project. Meanwhile, we have to work with a small number of articial material constants.
Could be switch from one database to

another without changing anything in the code using the material database?

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 40 of 41

Brain Teaser

Copy Constructor and Operators

Inheritance

virtual Operations

static

Design Patterns

A Factory Pattern
AbstractDB getEntry()

RealDatabase

HardcodedTestDB

We dene an abstract Database type. It is an interface (see UML diagram). This type is delivered by our singleton, i.e. codes work only with the interface. We implement the interface with a stupid class where we hardcode some material

constants (basically a big case statement).


Within the static operation, we then decide whether we deliver a real database or

our articial one.

8. Object-oriented Programming Introduction to C/C++, Tobias Weinzierl page 41 of 41

También podría gustarte