policy-injection

Policy based design and best practices - C++

允我心安 提交于 2020-06-23 22:26:09
问题 struct InkPen { void Write() { this->WriteImplementation(); } void WriteImplementation() { std::cout << "Writing using a inkpen" << std::endl; } }; struct BoldPen { void Write() { std::cout << "Writing using a boldpen" << std::endl; } }; template<class PenType> class Writer : public PenType { public: void StartWriting() { PenType::Write(); } }; int main() { Writer<InkPen> writer; writer.StartWriting(); Writer<BoldPen> writer1; writer1.StartWriting(); return 0; } I wrote the above code as part

Unity Interception in Derived Class

我怕爱的太早我们不能终老 提交于 2020-01-07 07:21:03
问题 I've got a situation where policy injection no longer works when I'm using a derived class. The classes involved look like this (basically an interface, an abstract base class, and an implementation class): public interface IRepository<T> { void Create(T iItem); } public abstract class ElmtRepository<T> : IRepository<T> { protected List<T> Items { get; set; } public ElmtRepository() { Items = new List<T>(); } public void Create(T iItem) { Items.Add(iItem); } } public class AcctPgmRepository :