Coder Social home page Coder Social logo

takaakit / design-pattern-examples-in-cpp Goto Github PK

View Code? Open in Web Editor NEW
33.0 3.0 10.0 47.48 MB

UML model and code examples of design patterns for C++. The model is created with Astah.

License: Creative Commons Zero v1.0 Universal

C++ 97.28% Makefile 2.58% C 0.14%
cpp uml gof design-patterns astah m-plus-plugin

design-pattern-examples-in-cpp's Introduction

Design Pattern Examples in C++

Model and code examples of GoF Design Patterns for C++.
This project is available for the following objectives:

  • To understand GoF Design Pattern examples in C++.
  • To understand the mapping between UML model and C++ code.
  • To try Model-Driven Development (MDD) using Astah and M PLUS plug-in.

UML model example:

C++ header file example:

// ˅

// ˄

#ifndef STRUCTURAL_PATTERNS_COMPOSITE_FILE_H_
#define STRUCTURAL_PATTERNS_COMPOSITE_FILE_H_

// ˅
#include <string>
#include "structural_patterns/composite/FileSystemElement.h"

using namespace std;

// ˄

class File : public FileSystemElement
{
	// ˅
	
	// ˄

private:

	const string name;

	const int size;

public:

	File(const string& name, const int size);

	~File();

	const string getName() const;

	const int getSize() const;

	// Print this element with the "upper_path".
	void print(const string& upper_path) const;

	// ˅
public:
	
protected:
	
private:
	File(const File&) = delete;
	File& operator=(const File&) = delete;
	File(File&&) = delete;
	File& operator=(File&&) = delete;
	
	// ˄
};

// ˅

// ˄

#endif	// STRUCTURAL_PATTERNS_COMPOSITE_FILE_H_

// ˅

// ˄

C++ source file example:

// ˅
#include <iostream>
#include "structural_patterns/composite/File.h"

using namespace std;

// ˄

File::File(const string& name, const int size)
	: name(name)
	, size(size)
	// ˅
    
	// ˄
{
	// ˅
	
	// ˄
}

File::~File()
{
	// ˅
	
	// ˄
}

const string File::getName() const
{
	// ˅
	return name;
	// ˄
}

const int File::getSize() const
{
	// ˅
	return size;
	// ˄
}

void File::print(const string& upper_path) const
{
	// ˅
	cout << upper_path << "/" << toString() << endl;
	// ˄
}

// ˅

// ˄

Installation on Windows

UML Modeling Tool

Visual Studio

  • Download and install Visual Studio.
    Check "Desktop development with C++" and "C++/CLI support" when installing.

Usage on Windows

Code Generation from UML

  1. Open the Astah file (model/DesignPatternExamplesInCpp.asta).
  2. Select model elements on the model browser of Astah.
  3. Click the Generate Code button.

    The generated code has User Code Area. The User Code Area is the area enclosed by "˅" and "˄". Handwritten code written in the User Code Area remains after a re-generation. View code example.
    For detailed usage of the tools, please see Astah Manual and M PLUS plug-in Tips.

Build and Run

  1. Open the solution file (design-pattern-examples-in-cpp.sln) in Visual Studio.
  2. Set up a startup project, and run it.

References

  • Gamma, E. et al. Design Patterns: Elements of Reusable Object-Oriented Software, Addison-Wesley, 1994
  • Hiroshi Yuki. Learning Design Patterns in Java [In Japanese Language], Softbank publishing, 2004

Licence

This project is licensed under the Creative Commons Zero (CC0) license. The model and code are completely free to use.

CC0

Other Language Examples

C#, Crystal, Go, Java, JavaScript, Kotlin, Python, Ruby, Scala, Swift, TypeScript

design-pattern-examples-in-cpp's People

Contributors

takaakit avatar tteshima avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.