VOIP Project: Patterns - Part 6

In order to develop good and stable software a software engineer should make use of the standardized accumulated knowledge of other engineers as well, know as patterns.

Patterns are defined by Shaffer as follow: “Experienced software designers learn and reuse patterns for combining software components …A primary goal of design patterns is to quickly transfer the knowledge gained by expert designers to newer programmers.” (A.Shaffer, 2013, p. 12), which shows that the patterns are a result of experience.
In this project are implemented several patterns and is paid a special attention to avoid the “Anti-Pattern” processes, which means "a common design pitfall. An anti-pattern is called this because many design patterns are designed to avoid such pitfalls.”(Ezust & Ezust, 2007, p. 342)

The singleton pattern is one of the patterns implemented in the project. Singleton pattern is a pattern which can be implemented in several high level programming languages and among them is c++ language as well, the language which is used when developing with the Qt Creator IDE, which is used during the development of this project.
In the book “An introduction to design patterns in c++ with Qt4” singleton pattern is explained as follow: “When we combine creation rules with a factory method that always returns the same singleton object, this is an example of the Singleton pattern.” (Ezust & Ezust, 2007, p. 360) This concept is implemented in the class DatabaseInteraction of this project. According the same book, singleton patter can be implemented as follow “… by making its constructor private or protected and providing an instance() function that creates a new instance if one does not already exist, but returns a pointer or reference to that instance if it does”.
In the DatabaseInteractionclass, the functions that implements the concept cited above is get_instance() function. As explained in the previous session the constructor of DatabaseInteractionclass is private, in order to forbid the creation of a new instance by calling the constructor an using the new keyword. As explained in the citation above, the get_instance() function returns the pointer to the existing instance if one instance of DatabaseInteractionclass exist, or it creates a new instance if it doesn’t exist. The singleton pattern in DatabaseInteractionclass makes possible the limitation of creation of a single connection with the MySQL database in one instance of the application, by making the database communication more organized and avoids the risk of having many database connections opened without need.

During the development of this project are used several patterns which are defined by the IDE Qt Creator, one of this patterns is composite pattern, which in the book “An introduction to design patterns in c++ with Qt4” is explained as follow “is intended to facilitate building complex (composite) objects from simpler (component) parts by representing the part-whole hierarchies as tree-like structures”(Ezust & Ezust, 2007, p. 196), which furthermore in that book is elaborated as a parent-child relationship.
In the VOIP School Network project developed, this pattern is widely implemented, especially in the classes generated by Qt Creator IDE, but also in the classes created manually during the development.

Another pattern supported very well by Qt tools is the observer pattern. This pattern is explained as follows “When a particular subject object changes state, it needs an indirect way to alert (and perhaps send additional information to) all the other objects that are listening to state-change events, known as observers.”(Ezust & Ezust, 2007, p. 360), the implementation of which are mentioned in the previous session, without linking it with the name of this pattern. The concept implemented in Qt that enables this pattern is signals and slots. When event happens a signal is emitted in order to notify the observer with which this signal is connected for an event that has happened in the object that emits the signal.
In the project this pattern is implemented in cases of a state change with the account object, when the account is registered in the PBX server, or in the call object, when there is an incoming call.

< Part 5: Design application Part 7: Preparing environment >

(please report broken link in the comment)

Comments

Popular posts from this blog

C++ Beginner: Lesson 4 - Tic Tac Toe game

C++ Beginner: Lesson 3 - Simple calculator

Free host and domain