Mapa mental
Chapter 7: Libraries and Design Patterns

Contenido del mapa
Chapter 7: Libraries and Design Patterns
7.1.1 Organizing Libraries: Dependency Management
- A dependency between two program elements exists if one reuses the other
- if building, using, or testing one (the reuser) requires the presence and correctness of the other one (the reused)
- In the case of classes, a dependency exists if the implementation of the reuser class must change whenever the interface of the reused class changes.
- This dependency is a compile time dependency if ProgElement1.h must be #included in ProgElement2.cpp to compile.
- It is a link time dependency if the object file ProgElement2.o contains symbols defined in ProgElement1.o.
- a change in the interface of ClassB might necessitate changes in the implementation of ClassA.
- • ClassA has a data member that is a ClassB object or pointer.
- • ClassA is derived from ClassB
- • ClassA has a function that takes a parameter of type ClassB
- • ClassA has a function that uses a static member of ClassB.
- • ClassA sends a message (e.g., a signal) to ClassB
- In each case, it is necessary to #include ClassB in the implementation file for ClassA.
- Code reuse, a valuable and important goal, always produces dependencies.
- Each time a header file is #included, it brings all of its own #includes along with it so that the number of dependencies grows accordingly
- Dependency management is an important issue for which a variety of tools have been developed
- • cinclude2dot,6 a Perl script that analyzes C/C++ code and produces a dependency graph. • Makedep,7 a C/C++ dependency generator for large software projects that parses all source files in a directory tree and constructs a large dependency file for inclusion in a Makefile.
- class ClassC; // forward declaration
- A forward declaration of ClassC is sufficient, however, because the class definition only uses a pointer to that class.
7.1.2 Installing Libraries
- After a library has been written and tested, it is installed at the end of the build process in the directory specified by the qmake variable DESTDIR.
- There is a thread on the subject8 at qtcentre.org that might save you a lot of time when you build your first DLL
7.2 Exercise: Installing Libraries
7.3 Frameworks and Components
- All large software projects are built on top of frameworks, and we discuss some of the more popular ones in use today.
- A framework is a (typically large) collection of general-purpose (or domain-specific) classes and conventions designed to improve the consistency of design.
- A framework has a well-documented public API
- To implement frameworks, design patterns are used.
- involves looking for pertinent objects and possible hierarchies.
- Qt is one of many open source object-oriented frameworks
- Some others worth knowing about are • boost15—An open source cross-platform library of C++ utility classes. • mono16—An open source implementation of Microsoft’s .NET, the API for C#, which is built on top of libgtk. • libgtk, libgtk++—Libraries that define the widgets used by the Gnome desktop, Mozilla, Dia, GAIM, GIMP, Evolution, OpenOffice, and many other open source programs. • wxWidgets17—Another C++ cross-platform widget toolkit. • Wt18—A Qt-like framework for building Web applications using boost and AJAX.19
7.4 Design Patterns
- Design patterns are efficient and elegant solutions to common problems in objectoriented software design.
- “Gang of Four,” analyzed 23 specific patterns.
- • A pattern name. • A description of the kinds of problems to which one might apply the pattern. • An abstract description of a design problem and how its solution can be obtained. • A discussion of the results and trade-offs that can occur when the pattern is applied.
- Design patterns are used for many different purposes. Most describe how to separate code by responsibility.
- subdivided into three categories: Creational, Structural, and Behavioral.
- Structural patterns describe how to organize objects and connect them
- Behavioral patterns describe how to organize code.
- Creational patterns describe how to organize code that manages object creation.
- design patterns are “descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context.”
- subdivided into three categories: Creational, Structural, and Behavioral.
- 7.4.1 Serializer Pattern: QTextStream and QDataStream
- With QDataStream, it is already possible to serialize and deserialize all QVariantsupported types, including QList, QMap, QVector, and others.
- the idea of the serializer pattern is to separate the I/O code from the class itself
- 7.4.2 AntiPatterns
- a commonly used programming practice that has proved to be ineffective, inefficient, or otherwise counterproductive
- • Software design antiPatterns
- • Input kludge—Failing to specify and implement the handling of possibly invalid input.
- • Interface bloat—Making an interface so powerful and complicated that it is hard to reuse or implement.
- • Race hazard—Failing to see the consequence of different orders of events
- • Object-oriented design antiPatterns
- • Circular dependency—Introducing unnecessary direct or indirect mutual dependencies between objects or software modules.
- • God Object—An object that has too much information or too much responsibility. This can be the result of having too many functions in a single class. It can arise from many situations, but it often happens when code for a model and view are combined in the same class.
- • Programming antiPatterns
- • Hard coding—Embedding assumptions about the environment of a system in its implementation.
- • Magic numbers—Including unexplained numbers in algorithms.
- • Magic strings—Including literal strings in code, for comparisons, as event types, etc.
- • Methodological antiPatterns
- • Copy and paste programming—Copying and modifying existing code without creating more generic solutions.
- • Reinventing the (square) wheel—Failing to adopt an existing, adequate solution and, instead, adopting a custom solution (which performs much worse than the existing one).
- This class is a model because it holds onto data and represents some abstract entity. However, this class also contains view code because of the createWidget() and getWidget() member functions. In addition, it contains serialization code specific to particular I/O streams.24 That is too much responsibility for a data model. This is an example of the Interface Bloat antiPattern
Imágenes y archivos del mapa
Información
- Descripción
- Computer Science Mapa Mental sobre Chapter 7: Libraries and Design Patterns, creado por Gideon Van el 04/08/2019.
- Creado por
- Gideon Van
- Visitas
- 1
- Valoración

