Golang Hello World Program

PROGRAM:

package main

import "fmt"

func main() {
fmt.Printf("hello, world\n")
}

OUTPUT:

Hello World

About

About Blog:

This blog provide tutorials on Programming languages such as C, C++ & Java

It has tutorial on Design Pattern using C++ Programming.


It also has Unix Shell scripting tutorial,  Linux commands and tricks.



About Me:

I am a software developer from India, I do program on C, C++, Golang & little bit JAVA.


I love Linux Operating system.

I am interested in Writing Blogs, contributing to technical forums and recently bike riding



Contact:

For queries write on sujinnew11@gmail.com




Proxy Pattern

Proxy Pattern comes under Structural Pattern.

According to Gang Of Four Intent of Proxy Pattern is to Provide a surrogate or placeholder for another object to control access to it.

UML DIAGRAM:




SAMPLE CODE:

#include <iostream>

using namespace std;

class Vote {
public:
    virtual void castVote(string name, int age) = 0;
};

class VoteSystem : public Vote {
public:
    void castVote(string name, int age)
    {
        cout << "NAME : " << name << ", AGE : " << age << " Casted Vote Successfully" << endl;
    }
};

class IndianVoteSystem : public Vote { // Proxy class
    Vote* voteOper;

public:
    IndianVoteSystem()
    {
        voteOper = new VoteSystem();
    }

    void castVote(string name, int age)
    {
        if (age >= 18) { // if age is more than 18 cast vote
            voteOper->castVote(name, age);
        }
        else {
            cout << age << " Years is Not Eligible Age to Cast Vote in India" << endl;
        }
    }
};

int main()
{
    string name;
    int age;

    Vote* indiaPoll = new IndianVoteSystem();

    cout << "Name ? "; cin >> name;
    cout << "Age  ? "; cin >> age;

    indiaPoll->castVote(name, age);

    return 0;

}


OUTPUT:

Name ? hirthik
Age  ? 16
16 Years is Not Eligible Age to Cast Vote in India

Name ? sharma
Age  ? 34
NAME : sharma, AGE : 34 Casted Vote Successfully

Name ? rahul
Age  ? 18
NAME : rahul, AGE : 18 Casted Vote Successfully

                                               INDEX - OTHER DESIGN PATTERNS

Bridge Pattern

Bridge Pattern is one of the Structural Design Pattern.

According to GoF intent of Bridge Pattern is to Decouple an abstraction from its implementation so that the two can vary independently.


SAMPLE CODE:

#include <iostream>

using namespace std;

class IColour {
public:
    virtual void paintColour() = 0;
};

class RedColour : public IColour {
public:
    void paintColour()
    {
        cout << "RED Colour Paint" << endl;
    }
};

class GreenColour : public IColour {
public:
    void paintColour()
    {
        cout << "GREEN Colour Paint" << endl;
    }
};

class IShape {
protected:
    IColour* colour;
public:
    IShape (IColour* colour) {
        this->colour = colour;
    }
    virtual void draw() = 0;
};

class Circle : public IShape {
public:
    Circle(IColour* c) : IShape(c) {
    }

    void draw()
    {
        cout << "Draw a Cirle With ";
        colour->paintColour();
    }
};

class Square : public IShape {
public:
    Square(IColour* c) : IShape(c) {
    }

    void draw()
    {
        cout << "Draw a Square With ";
        colour->paintColour();
    }
};

int main()
{
    RedColour redPaint;
    GreenColour greenPaint;
    IShape* circleImage, *squareImage;

    circleImage = new Circle(&redPaint);
    circleImage->draw();

    squareImage = new Square(&greenPaint);
    squareImage->draw();

    return 0;

}


OUTPUT:

Draw a Cirle With RED Colour Paint

Draw a Square With GREEN Colour Paint

                                               INDEX - OTHER DESIGN PATTERNS

Template Method Pattern

Template Method Pattern is one of the Behavioral design pattern.

According to Gang Of Four intent of Template Method Pattern is to Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.


SAMPLE CODE:

#include <iostream>

using namespace std;

class CoffeeTemplate {
private:
    virtual void boilWater()
    {
        cout << "  * Boiling Water" << endl;
    }
    virtual void addMilk()
    {
        cout << "  * Adding Milk" << endl;
    }
    void addSugar()
    {
        cout << "  * Adding Sugar" << endl;
    }

    virtual void addCoffee() = 0;

public:
    void makeCoffee() /* Template Method */
    {
        cout << "Start Making Coffee" << endl;
        boilWater();
        addMilk();
        addCoffee();
        addSugar();
        cout << "Tasty Coffee Ready Enjoy!!!" << endl << endl;
    }
};

class NescafeeCoffee : public CoffeeTemplate {
    void addCoffee()
    {
        cout << "  * Adding Nescafee Coffee Podwer" << endl;
    }
};

class BruCoffee : public CoffeeTemplate {
    void addCoffee()
    {
        cout << "  * Adding Bru Coffee Powder" << endl;
    }
};

class SunriseCoffee : public CoffeeTemplate {
    void addCoffee()
    {
        cout << "  * Adding Sunrise Coffee Powder" << endl;
    }
};

int main()
{
    CoffeeTemplate* coffee = new BruCoffee();
    coffee->makeCoffee();

    coffee = new SunriseCoffee();
    coffee->makeCoffee();
    return 0;
}

OUTPUT:

Start Making Coffee
  * Boiling Water
  * Adding Milk
  * Adding Bru Coffee Powder
  * Adding Sugar
Tasty Coffee Ready Enjoy!!!

Start Making Coffee
  * Boiling Water
  * Adding Milk
  * Adding Sunrise Coffee Powder
  * Adding Sugar
Tasty Coffee Ready Enjoy!!!

                                               INDEX - OTHER DESIGN PATTERNS