Skip to content

Instantly share code, notes, and snippets.

View day02's full-sized avatar

day day02

View GitHub Profile
#include <iostream>
// abstract class
struct game {
explicit game(const std::uint32_t players): m_players(players) {}
game(game&) = delete;
game(game&&) = delete;
game& operator=(game&) = delete;
game& operator=(game&&) = delete;
~game() = default;
#include <iostream>
#include <functional>
#include <memory>
#include <string>
// single responsibility principle
struct coffee_maker {
void get_coffee(const std::string &serve) const {
std::cout << "get coffee " << serve << std::endl;
}
#include <iostream>
#include <memory>
using coordinate_t = std::int32_t;
using dimension_t = std::uint32_t;
// abstract definition
struct rectangle {
public:
#include <iostream>
#include <array>
#include <numeric>
struct game {
using ability_t = long;
explicit game(const ability_t strength,
const ability_t agile) : m_abilities{strength, agile} {}
#include <iostream>
#include <memory>
using cord_t = std::int32_t;
using dim_t = std::uint32_t;
// abstracts
struct renderer {
virtual void render(const cord_t x, const cord_t y, const dim_t radius) const = 0;
using unique_t = std::unique_ptr<renderer>;
/**
* Whenever the creation of new object requires setting many parameters and
* some of them (or all of them) are optional.
* The concern of building object should be in the separate entity.
* Testing & understanding a constructor with many input arguments gets
* exponentially more complicated. More expressive code. MyClass o = new
* MyClass(5, 5.5, 'A', var, 1000, obj9, "hello"); MyClass o =
* MyClass.builder().a(5).b(5.5).c('A').d(var).e(1000).f(obj9).g("hello"); You
* can see which data member is being assigned by what & even change the order
* of assignment.
#include <iostream>
#include <string>
#include <boost/signals2.hpp>
struct query
{
// Command
std::int32_t m_cnt{0};
};
/**
What is the important aspect of the Command Design Pattern?
1. Interface separation: the invoker is isolated from the receiver.
2. Time separation: stores a ready-to-go set of instructions that can be scheduled.
What is the reason behind using the Command Design Pattern?
– Decouple the sender & receiver of the command
#include <type_traits>
#include <sstream>
#include <iostream>
struct shape
{
virtual operator std::string() = 0;
};
struct circle : public shape
#include <iostream>
struct alarm {
void on() {
std:: cout << "Alarm is on" << std::endl;
}
void off() {
std::cout << "Alarm is off" << std::endl;
}
};