Questions tagged [creation-pattern]
17 questions
10
votes
1 answer
Registry pattern Vs Service locator pattern Vs Dependency Injection Container
Is there any difference between them rather than set and get objects in an array by key?
class Registry
{
private $container=array();
public static function Set($name,$object){
self::$container[$name]=$object;
}
public static function…

Namjith Aravind
- 404
- 6
- 12
5
votes
2 answers
Should C++ abstract factory provide destroy method for constructed objects?
Consider the following interface (dumb pointers are used because we are still in
C++98)
class WidgetMaker {
virtual Widget* makeWidget() = 0;
};
With the following likely implementation
class SpecificWidgetMaker: public WidgetMaker {
…

Muxecoid
- 1,193
- 1
- 9
- 22
3
votes
1 answer
Creational Patterns suggestion
I'm struggling to find a good way to handle a problem that seems to be nice.
My entire model relies on the concept of pricing strategies. These strategies calculate a specific price based on rules. Rules just how to calculate the price for a given…
user4478810
1
vote
0 answers
How to create an object of derived class based ctor parameters without exclicitly calling the derived
I have simplified my true issue into the following example:
namespace Cars
{
public class Program
{
public static void Main(string[] args)
{
Car car1 = Car.Create(new Driver(1, "A",…

LEyahoo
- 83
- 1
- 9
1
vote
1 answer
how to avoid "cascading if\case"-statements in a factory class
I have to create an object based on a specific situation. I read, that the solution could be the Factory Pattern, but in my case it has a lot of disadvantages.
For instance: I have an application that manages animals. At some point a client gives…

ale666
- 41
- 4
1
vote
4 answers
What creational pattern I should use?
My program have two classes; both derive from same base class.
class A : MyBase
{
internal A(InitVal initVal)
}
class B : MyBase
{
internal B(InitVal initVal)
}
InitVal is another class which is injected through constructor. This class is…

Amit Joshi
- 15,448
- 21
- 77
- 141
1
vote
2 answers
Generic abstract builder properties needs casting
I've build a generic (abstract) builder which will provide basic implementation
for entity builders that will be used during testing.
This is the entity base class:
public abstract class Entity : IObjectState
{
[NotMapped]
public ObjectState…

grmbl
- 2,514
- 4
- 29
- 54
1
vote
2 answers
Is there a design pattern for creating a prototype with only some values differing?
The client uses them via the base class (java code) :
BaseClass baseObj1 = new DerivedClass("valueofreqdfeature");
//the required feature gets added to the map in the base class
Map features =…

shrewquest
- 541
- 1
- 7
- 22
1
vote
2 answers
How to create object based on boolean condition?
I have an Item object having 4 String fields and 3 boolean fields.
I have to construct this object based on the 3 boolean variables.
The target is whenever any one of the boolean variable is true we have to create the object having that/those…

anirban
- 674
- 1
- 7
- 21
1
vote
1 answer
make_unique, factory method or different design for client API?
We have a library with that publishes an abstract base class:
(illustrative psudocode)
/include/reader_api.hpp
class ReaderApi
{
public:
static std::unique_ptr CreatePcapReader ();
virtual ~ReaderApi() = 0;
};
In the library…

John Dibling
- 99,718
- 31
- 186
- 324
0
votes
2 answers
Abstract Factory Design Pattern in Software Design & Architecture
I am working to understand Abstract Factory design pattern and facing an error in many examples. As in below class diagram:
Here in this example Abstract Factory class which must be an interface have the responsibility to create Abstract Product…

ABU-ZHAR
- 37
- 6
0
votes
1 answer
How to avoid need for User code knowing and instantiating concrete Strategy in Strategy Pattern
Strategy pattern decouples the context code and strategies (or algorithm or policy) being used by it. It has an advantage over Template Pattern as it enables dynamic behavior change and uses composition with delegation to achieve it. Below is such…

nits.kk
- 5,204
- 4
- 33
- 55
0
votes
1 answer
Eiffel: best practices for creation procedures
Animal
deferred class ANIMAL
inherit
ANY
redefine
default_create
end
feature
creator: like Current
guts: GUTS
default_create
do
create guts
end
make_malformed
…

Pipo
- 4,653
- 38
- 47
0
votes
1 answer
Creating new objects in a java switch statement. Alternative design pattern available?
Working on a project where the flavour of the month seems to be using switch statements and enums to decide what concrete class instance to create.
Is there an alternative design pattern that could be considered for object creation, taking into…

juckky
- 493
- 3
- 13
0
votes
0 answers
Is it possible to use factory method with builder pattern?
I'm having this question because:
I know that builder pattern (as far as I understand) should be used when you have to create complex objects (their constructors are large) and factory is for having a class who is responsible for instantiating…

Teddy S.
- 33
- 8