Professional Documents
Culture Documents
10 - Large Scale C++ Software Design PDF
10 - Large Scale C++ Software Design PDF
John Lakos
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 1 / 27
Large Scale C++ Software Design
Motivation
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 2 / 27
Large Scale C++ Software Design
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 3 / 27
Cyclic Link-Time Dependencies
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 4 / 27
Cyclic Link-Time Dependencies
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 5 / 27
Excessive Link-Time Dependencies
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 6 / 27
Excessive Link-Time Dependencies
//str.h
class String{
//str.cpp
char* d_string_p;
#include "str.h"
int d_length;
#include "sun.h"
int d_Size;
#include "Asterix.h"
int d_Count;
//...
//...
//lots of includes
public:
//...
String();
#include "everyone.h"
String(const String&);
#include "theirmother.h"
String(const char*);
String::String()
String(const char c);
:d_String(0)
~String();
,d_length(0)
//
,d_size(0)
//...27 pages omitted
,d_Count(0)
//
//...
int isPalindrome();
//...
int isNameofFamousActor();
};
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 7 / 27
Excessive Link-Time Dependencies
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 8 / 27
Excessive Compile-Time Dependencies
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 9 / 27
Excessive Compile-Time Dependencies
//myerror.h
#ifndef MY ERROR H
#define MY ERROR H
struct MyError
{
enum Codes
{
SUCCESS = 0,
WARNING,
IO ERROR,
// . . .
READ ERROR,
WRITE ERROR,
// . . .
BAD STRING,
BAD FILENAME,
// . . .
MARTIANS HAVE LANDED,
// . . .
}
}
#endif
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 10 / 27
Reuse is not without cost!!
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 11 / 27
To Summarize
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 12 / 27
What are Dependencies?
Notations
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 13 / 27
What are Dependencies?
IsA
class B{/*...*/};
class D : public B{/*...*/};
D inherits from B
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 14 / 27
What are Dependencies?
//Intset class
int operator==(const Intset&,const Intset&)
{
IntsetIter iter = ...
}
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 15 / 27
The ”DependsOn” relation
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 16 / 27
Implied Dependencies
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 17 / 27
Compile-Time Dependencies
//str.h
#include "chararray.h"
class String{
charArray d_array; //Has A
//...
};
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 18 / 27
Link-Time Dependencies
//word.h //str.h
#ifndef INCLUDED_WORD #ifndef INCLUDED_STR
#define INCLUDED_WORD #define INCLUDED_STR
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 19 / 27
Link-Time Dependencies
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 20 / 27
Ensure Reliable Quality Software
Physical Heirarchy
Heirarchy among components as defined by the DependsOn realtion is
analogous to logical heirarchy implied by layering.(Physical heirarchy
is not “logical inheritance“ among classes altough inheritance implies
physical dependencies.
Avoiding cyclic physical dependencies is core to effective
understanding,maintainability testing and re-use of code.
Well designed interfaces are small, easy to understand, easy to use,
yet these interfaces make user-level testing expensive.
Complex software systems should be designed to have low level
objects with well defined interfaces, allowing each object to be tested
in isolation. these objects must be integrated via layering into a
sequence of increasing complex sub systems again allowing each sub
system to be tested in isolation
The final product must also be tested to ensure customer quality
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 21 / 27
Acyclic Physical Dependencies
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 22 / 27
Acyclic Physical Dependencies
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 23 / 27
High Quality Designs are Levelizable
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 24 / 27
High Quality Designs are Levelizable
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 25 / 27
Is this Design Levelizable ?
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 26 / 27
Yes
Girish Loganathan (LSS Erlangen) Large Scale C++ Software Design 18/06/2012 27 / 27