Skip to content

Instantly share code, notes, and snippets.

View rajkumar-p's full-sized avatar

Rajkumar rajkumar-p

View GitHub Profile
@rajkumar-p
rajkumar-p / files_purger.hpp
Created September 14, 2019 05:14
FilesPurger - Stratergy Pattern
class FilesPurger {
public:
virtual ~FilesPurger();
virtual void purge(const std::string &root) = 0;
};
@rajkumar-p
rajkumar-p / disk_janitor.hpp
Last active September 14, 2019 05:09
DiskJanitor - Strategy Pattern
class DiskJanitor {
private:
std::unique_ptr<FilesPurger> _purger;
public:
DiskJanitor(std::unique_ptr<FilesPurger> purger);
void clean_files(const std::string &root);
};
@rajkumar-p
rajkumar-p / storage_manager.cpp
Last active August 31, 2019 14:41
Storage Manager - Delegate Pattern
class TextData {
private:
std::string _data;
std::unique_ptr<SpellChecker> _spell_checker;
std::unique_ptr<StorageManager> _storage_manager;
...
public:
int save(const std::string &loc,
const TextData &text_data)
@rajkumar-p
rajkumar-p / storage_manager.hpp
Created August 31, 2019 14:14
Storage Manager - Delegate Pattern
class StorageManager {
virtual int save(const std::string &loc,
const TextData &text_data) = 0;
};
class TextFileStorageManager : public StorageManager {
int save(const std::string &loc,
const TextData &text_data);
};
@rajkumar-p
rajkumar-p / advanced_spell_checker.cpp
Created August 31, 2019 14:01
Advanced Spell Checker - Delegate Pattern
TextData text_data("Some data.",
std::unique_ptr<SpellChecker>(new SpellChecker())
);
text_data.spell_check();
text_data.set_spell_checker(
std::unique_ptr<SpellChecker>(new AdvancedSpellChecker())
);
text_data.spell_check();
@rajkumar-p
rajkumar-p / advanced_spell_checker.hpp
Created August 31, 2019 10:58
Advanced Spell Checker - Delegate Pattern
class AdvancedSpellChecker : public SpellChecker {
std::vector<std::string> spell_check(const std::string &data);
};
@rajkumar-p
rajkumar-p / text_data.hpp
Created August 31, 2019 10:42
Text Data - Delegate Pattern
class TextData {
private:
std::string _data;
std::unique_ptr<SpellChecker> _spell_checker;
public:
TextData(const std::string &s,
std::unique_ptr<SpellChecker> sc);
TextData(const TextData &other);
TextData& operator=(const TextData &other);
@rajkumar-p
rajkumar-p / spell_checker.hpp
Created August 31, 2019 10:31
Spell Checker - Delegate Pattern
class SpellChecker {
private:
std::set<std::string> _dict;
public:
SpellChecker();
virtual ~SpellChecker();
virtual std::vector<std::string> spell_check(const std::string &data);
};
@rajkumar-p
rajkumar-p / text_data.hpp
Created August 31, 2019 04:20
TextData Interface - Delegate Pattern
class TextData {
private:
std::string _data;
public:
// Methods
};
@rajkumar-p
rajkumar-p / composite.cpp
Created August 28, 2019 18:59
Client - Composite Pattern
std::unique_ptr<File> home(
std::make_unique<DirectoryFile>("/users/raj", 700)
);
std::unique_ptr<File> f1(
std::make_unique<RegularFile>("file1", 644)
);
std::unique_ptr<File> f2(
std::make_unique<RegularFile>("file2", 644)
);