-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first rough version of Template Method.
- Loading branch information
1 parent
9fbab5d
commit 2f0420c
Showing
9 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "Application.h" | ||
|
||
#include "Document.h" | ||
#include "DocumentStore.h" | ||
|
||
#include <iostream> | ||
|
||
Application::Application() { | ||
_docs = new DocumentStore; | ||
} | ||
|
||
Application::~Application() { | ||
delete _docs; | ||
} | ||
|
||
void Application::AddDocument() { | ||
std::cout << "Adding document to application." << std::endl; | ||
} | ||
|
||
void Application::OpenDocument(const char* name) { | ||
if (!CanOpenDocument(name)) { | ||
// cannot handle this document | ||
return; | ||
} | ||
|
||
Document* doc = DoCreateDocument(); | ||
|
||
if (doc) { | ||
_docs->AddDocument(doc); | ||
AboutToOpenDocument(doc); | ||
doc->Open(); | ||
doc->DoRead(); | ||
} | ||
} | ||
|
||
Document* Application::DoCreateDocument() { | ||
std::cout << "Creating a document." << std::endl; | ||
Document* doc = new Document; | ||
return doc; | ||
} | ||
|
||
bool Application::CanOpenDocument(const char* name) { | ||
std::cout << "Checking whether we can open document " << name << "." << std::endl; | ||
return true; | ||
} | ||
|
||
void Application::AboutToOpenDocument(const Document* doc) { | ||
std::cout << "About to open document " << doc << "." << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef APPLICATION_H | ||
#define APPLICATION_H | ||
|
||
class Document; | ||
class DocumentStore; | ||
|
||
class Application { | ||
public: | ||
Application(); | ||
virtual ~Application(); | ||
|
||
void AddDocument(); | ||
void OpenDocument(const char* name); | ||
|
||
virtual Document* DoCreateDocument(); | ||
virtual bool CanOpenDocument(const char* name); | ||
virtual void AboutToOpenDocument(const Document* doc); | ||
private: | ||
DocumentStore* _docs; | ||
}; | ||
|
||
#endif // APPLICATION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
set(template_method_SRCS | ||
Application.cpp | ||
Document.cpp | ||
DocumentStore.cpp) | ||
|
||
add_library(template_method_lib SHARED ${template_method_SRCS}) | ||
target_include_directories(template_method_lib PUBLIC ./) | ||
|
||
add_executable(template_method1 main1.cpp) | ||
target_link_libraries(template_method1 template_method_lib) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "Document.h" | ||
|
||
void Document::Save() {} | ||
void Document::Open() {} | ||
void Document::Close() {} | ||
void Document::DoRead() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef DOCUMENT_H | ||
#define DOCUMENT_H | ||
|
||
class Document { | ||
public: | ||
void Save(); | ||
void Open(); | ||
void Close(); | ||
virtual void DoRead(); | ||
}; | ||
|
||
#endif // DOCUMENT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "DocumentStore.h" | ||
|
||
#include <iostream> | ||
|
||
void DocumentStore::AddDocument(const Document* doc) { | ||
std::cout << "Adding document " << doc << " to the document store." << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef DOCUMENT_STORE_H | ||
#define DOCUMENT_STORE_H | ||
|
||
class Document; | ||
|
||
class DocumentStore { | ||
public: | ||
void AddDocument(const Document* doc); | ||
}; | ||
|
||
#endif // DOCUMENT_STORE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "Application.h" | ||
|
||
int main() | ||
{ | ||
Application app; | ||
app. OpenDocument("SomeDocument"); | ||
} |