Posts

Showing posts from September, 2017

Bridge Design Pattern

Image
This is structural design pattern. The bridge pattern is a design pattern that separates the abstract elements of a class from its technical implementation. This provides a cleaner implementation of real-world objects and allows the implementation details to be changed easily. The bridge pattern is used to separate the abstract elements of a class from the implementation details. For example, the abstract elements may be the business logic of an application. They can be created without any knowledge of the implementation details of their data access or interoperability with the operating system. The pattern provides the means to replace the implementation details without modifying the abstraction. This permits, for example, changing operating systems, databases, etc. with no impact to the business logic. Example: In automate message sending application there are mainly 3type of mode to send message phone call, sms & email. There is no issue if there are less number of sendi...

Strategy Design Pattern

Image
This is one of behavioural design pattern. The strategy pattern is a design pattern that allows a set of similar algorithms to be defined and encapsulated in their own classes. The algorithm to be used for a particular purpose may then be selected at run-time according to your requirements. The strategy pattern is used to create an interchangeable family of algorithms from which the required process is chosen at run-time. This allows the behavior of a program to change dynamically according to configuration details or user preferences. It also increases flexibility by allowing new algorithms to be easily incorporated in the future. Checklist 1. Create a abstract base class which contains behaviors. 2. Implements the behaviors in derived classes. 3. Define a strategy class which aggregates with  behavior class. Example : While traveling, we can choose any of transport service; bus, cab, train, bike. Each travel service have their estimate time & cost of travel. Trav...

Builder Design Pattern

Image
Builder Design pattern is one of the creational design pattern. This pattern allows for the step-by-step creation of complex objects using the correct sequence of actions. The construction is controlled by a director object that only needs to know the type of object it is to create. Example #include<iostream> using namespace std; class Meal {     public:         string Sandwich;         string Drink;         string Sideitem;         int price;         void ServeMeal()         {             cout<<"Your order please"<<endl;             cout<<Sandwich<<endl<<Drink<<endl<<Sideitem<<endl<<endl;          ...

STL Tutorial

Image
https://www.cs.helsinki.fi/u/tpkarkka/alglib/k06/lectures/containers.html Vector:  Vectors are sequence containers that have dynamic size. In other words, vectors are dynamic arrays. Just like arrays, vector elements are placed in contiguous storage location so they can be accessed and traversed using iterators. Vector provide random access. Insertions and deletions in the beginning or in the middle are slow. #include <iostream> #include <vector> using namespace std; int main()  {    vector<int> vec;    int i;    cout << "vector size = " << vec.size() << endl;    for(i = 0; i < 5; i++) {       vec.push_back(i);    }    cout << "extended vector size = " << vec.size() << endl;    for(i = 0; i < 5; i++) {       cout << "value of vec [" << i << "] = " << vec[i] <...