264 questions
2
votes
1
answer
67
views
How to type hint a python factory method returning different types?
I am working on a generic framework with the goal to solve different but related problems. A problem consists of data and a bunch of algorithms operating on this data. Data and algorithms may vary ...
0
votes
0
answers
53
views
Possible to intercept class instantiation in PHP?
Is there a way in PHP that, every time I instantiate a new class — e.g. $o = new SomeClass() — I can "intercept" that and actually return some other class?
Or, more specifically, I want to ...
0
votes
1
answer
59
views
Is there a simple way of accessing a function from another Activity in Android Studio
This is a quick question that I hope someone can help me out with. im fairly new to AS and I hope I am not over thinking this, but I'm a big beleiver in studying a topic fully, and have just spent the ...
0
votes
4
answers
237
views
Why to use factory pattern
I am trying to understand the Factory Method design pattern and i have come across multiple questions similar to the one on my mind but my question still remains unanswered.
this is the article I am ...
2
votes
0
answers
60
views
How can we reduce a multi-functional class with conditional logic into fundamental classes with specific logic - C# ASP.NET Core
In an ASP.NET Core EF application, I have a CentralDesignObject with many types of related data, and a significant amount of derived / calculated values based on the information applied to the ...
1
vote
1
answer
144
views
Why is class and subclass reduction a particular consequence of the Prototype design pattern?
I read the Design Patterns book (written by the Gang of Four) and I'm now recapping on the Prototype Design pattern. In the consequence section, of the Prototype design pattern, (explained on page 119 ...
0
votes
1
answer
139
views
Identify the best architecture for sending different types email in ASP.NET Core
I have defined an interface IEmailManager as having send method. The email controller is using its concrete type EmailManager as a constructor dependency that sends the email.
public interface ...
1
vote
1
answer
99
views
Override the __init__ method of a base class to edit a string literal
So let's consider the following classes. I have no control over classes A, B, and C and can't change the implementation.
class A(object):
def __new__(cls, root=None):
if root == "Some ...
4
votes
4
answers
551
views
Joshua Bloch Item #1 Static Factory Methods Instead of Constructors - Object creation
Source of Question
I was wondering about the following advantage of Static Factory Methods described by Joshua Blochs "Effective Java", 3rd edition in item #1:
A second advantage of static ...
-1
votes
1
answer
209
views
Constant expression required in switch statements
have this enum file containing some information:
public enum Constants {
AGED_BRIE("Aged Brie");
private final String label;
Constants(String label) {
this.label = ...
2
votes
2
answers
3k
views
Using Jackson, how can I deserialize values using static factory methods that return wrappers with a generic type?
Using Jackson, I want to deserialize some values into generic wrapper objects for which I have a specific static factory method for each type.
However, Jackson does not seem to pick up on this layer ...
0
votes
1
answer
281
views
Python Factory Method Suggestions
I would like to ask you to help me out with my factory method. I have to handle multiple and periodic csv objects, each of which has its own properties, thus its own class. The only way I can tell ...
1
vote
0
answers
76
views
Are function-local objects guaranteed to be returned as rvalue-references? [duplicate]
In the following simple code I return a function local object from a function (factory function). Does the C++ standard guarantee in every case that this object is being returned as an rvalue ...
1
vote
0
answers
441
views
How to write mypy-safe factory for getting a class instance based on required class attributes?
Context
I'm using ABC to create a bunch of sub-classes like so:
from abc import abstractmethod, ABC
class Person(ABC):
@property
@abstractmethod
def person_name(self) -> str:
...
1
vote
1
answer
129
views
Type specific method is unavailable for a var returned with `some` directive
Consider a factory method pattern implementation:
import UIKit
protocol TransportProtocol: CustomStringConvertible {
func techReview()
}
// Make default implemetation opposed to @objc optional ...
2
votes
2
answers
3k
views
If I can have multiple factory methods in a creator class, why would I ever need the abstract factory pattern?
The abstract factory pattern is useful when we have families of related classes, and we want to instantiate them without relying on the implementation. However, what's wrong with using the factory ...
5
votes
3
answers
2k
views
Static factory method for trait
I'm just learning Rust, so maybe I just didn't get some concepts correctly.
I have a trait with some implementations:
trait Abstract {
fn name(&self) -> &str;
}
struct Foo {}
struct ...
0
votes
1
answer
190
views
Is there any way to keep track of how many objects I have created with a factory function in JavaScript?
Let's say I have a factory like this:
const itemFactory = () => {
const itemName = ''
const firstMethod = () => {
// something goes here
}
return { itemName, firstMethod ...
0
votes
1
answer
222
views
Multi-file Factory method [duplicate]
There are two classes Base and Derived.
Base.h:
class Base {
public:
Base* create_obj();
};
And Base.cpp :
#include "Base.h"
Base* Base::create_obj() {
return new Derived();
};
and ...
1
vote
1
answer
249
views
Is it a good practice to add object instance attributes according to some condition?
I have the following python code, where I create a food object, which adds instance attributes according to the food type:
class Food:
def __init__(self, type):
self.type=type
...
5
votes
4
answers
2k
views
Simple factory VS Factory Method (why use factory method at all)
Im trying to learn patterns and got to Factory, I understand the concept of simple factory and factory method, I know how they work, what I cant understand is what is the benefit of factory method ...
1
vote
2
answers
616
views
Factory Method: "Patterns in Java" by Mark Grand vs GoF interpretation
I'm learning Java design patterns by "Patterns in Java", volume 1 by Mark Grand (Factory Method specifically). My point is to highlight difference between closest patterns for myself. There ...
2
votes
1
answer
2k
views
How is java.util.Calendar an example for factory method design pattern?
Refactoring Guru provides a good example for factory method.
In that example there are Common product interface, Concrete products, Base creator and Concrete creator. But in Calendar, I find only ...
1
vote
1
answer
867
views
Applicability for the Factory Method Pattern
I am confused at the factory-method pattern.
The below code is from "https://www.oodesign.com/factory-method-pattern.html"
public interface Product { � }
public abstract class Creator
{
...
0
votes
2
answers
590
views
How to change pointer from base to derived class inside a function
I would like to create some kind of factory function, but instead of returning a pointer to a certain class object, I would like to pass a pointer to the base class to a function as an argument. What ...