factory-pattern

Why did I get the error “error C2259: … cannot instantiate abstract class”?

我的未来我决定 提交于 2019-12-20 06:35:21
问题 Any help is appriciated. I'm working on a C++ factory pattern and i get this error. 1>c:\users\brian\documents\visual studio 2010\projects\cst276lab_3\guitar.hpp(456): error C2259: 'ElectricGuitarComponentFactory' : cannot instantiate abstract class This is my code: ///////////////////////guitar class//////////////////// class Guitar { private: std::string _name; protected: mutable std::auto_ptr< HeadStock > _HeadStock; protected: mutable std::auto_ptr< NeckStrap > _NeckStrap; protected:

Why can't I get Type.GetType() to find the type of my plugin instance referenced in app.config?

吃可爱长大的小学妹 提交于 2019-12-20 02:32:31
问题 So here's the deal. I've got my solution which has a few projects in it: A wrapper project - this is just a console app that's currently standing in for a windows service during debugging. A worker project - this contains the guts of the code. This way I can easily debug the code for the windows service without the headache. A plugin library project - This contains a plugin factory to new up a concrete instance of a plugin. A plugin project - This contains a concrete implementation of my

The best way to implement Factory without if, switch

╄→尐↘猪︶ㄣ 提交于 2019-12-20 01:41:12
问题 I was looking through many approaches to implement a Factory pattern in Java and still couldn't find a perfect one which doesn't suffer from both if/switch plus doesn't use reflection. One of the best that I found was inside Tom Hawtin's answer here: https://stackoverflow.com/a/3434505/1390874 But my biggest concern is that it stores a HashMap of Anonymous classes in a memory. The question is what do people think about using Class.newInstance() in addition to Tom Hawtin's answer? This will

Python, doing conditional imports the right way

我怕爱的太早我们不能终老 提交于 2019-12-19 06:05:51
问题 Right now I have a class called A. I have some code like this.. from my.package.location.A import A ... foo = A.doSomething(bar) This is great. But now I have a new version of A called A, but in a different package, but I only want to use this other A in a certain scenario. So I can do something like this: if(OldVersion): from my.package.location.A import A else: from new.package.location.A import A ... foo = A.doSomething(bar) This works fine. But it is ugly. How can I do this better? I

Python, doing conditional imports the right way

风格不统一 提交于 2019-12-19 06:05:36
问题 Right now I have a class called A. I have some code like this.. from my.package.location.A import A ... foo = A.doSomething(bar) This is great. But now I have a new version of A called A, but in a different package, but I only want to use this other A in a certain scenario. So I can do something like this: if(OldVersion): from my.package.location.A import A else: from new.package.location.A import A ... foo = A.doSomething(bar) This works fine. But it is ugly. How can I do this better? I

Factory / Abstract Factory confusion

白昼怎懂夜的黑 提交于 2019-12-18 10:29:14
问题 After ~10 months of procedural PHP, I'm now trying to wrap my head around basic OOP principles and design patterns. This is a hobby, and I haven't nearly as much time as I'd like to pursue it, so please forgive the rather low level of this question. My site (currently 100% procedural) is at heart a library. Visitors send the Library script 2 datapoints - an item type and item code . Library.php uses the item type to select an include, and the include grabs the code to hit the database and

Why am I getting “The type parameter must be invariantly valid…” error?

旧巷老猫 提交于 2019-12-18 05:56:18
问题 I'll attempt to shorten this code example: public interface IThing { //... Stuff } public class Thing1 : IThing { } public class Thing2 : IThing { } public interface IThingView<out T> { ICollection<T> ViewAll(); } public class ThingView<T> : IThingView<T> { ICollection<T> ViewAll() { return new List<T>(); } // There's a big operation here } public interface IThingViewerFactory { public IThingView<IThing> Build(string Which); } public class ThingViewerFactory { public IThingView<IThing> Build

Best way to implement the Factory Pattern in Java

不想你离开。 提交于 2019-12-17 18:44:02
问题 I am trying to write a Factory Pattern to create either a MainMode or a TestMode in my program. The code I was previously using to create these objects was: play = (isMode) ? new MainMode(numberRanges, numberOfGuesses) : new TestMode(numberRanges, numberOfGuesses, randNo()); My Game (play) would either create a MainMode object or a TestMode object depending on a boolean value (isMode). As you can see I am adding an extra value into my TestMode object (randNo()). This value is used within

What are the differences between Abstract Factory and Factory design patterns?

China☆狼群 提交于 2019-12-16 19:45:01
问题 I know there are many posts out there about the differences between these two patterns, but there are a few things that I cannot find. From what I have been reading, I see that the factory method pattern allows you to define how to create a single concrete product but hiding the implementation from the client as they will see a generic product. My first question is about the abstract factory. Is its role to allow you to create families of concrete objects in (that can depend on what specific

Is this the correct way to use and test a class that makes use of the factory pattern?

爷,独闯天下 提交于 2019-12-14 03:42:26
问题 I don't have a lot of experience with the factory pattern and I've come across a scenario where I believe it is necessary but I'm not sure the I've implemented the pattern correctly and I'm concerned about the impact it's had on the readability of my unit tests. I've created a code snippet that approximates (from memory) the essence of the scenario I am working on at work. I'd really appreciate it if someone could take a look at it and see if what I've done seems reasonable. This is the class