abstract-factory

How to inject a dependency when testing an Android activity without a third-party framework?

主宰稳场 提交于 2020-01-24 02:58:45
问题 I want to test an Android activity CommentActivity that normally constructs and uses an instance of CommentsDataSource (both are classes that I wrote). public class CommentActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { : CommentsDataSource = new CommentsDataSource(..); : } : } I'm willing to create MockCommentsDataSource myself and would like to avoid using a third-party mocking framework. (Why? Because I'm a teaching trying to reduce the amount of

What is this Design Pattern?

喜欢而已 提交于 2020-01-04 05:08:06
问题 I read the Wikipedia articles on FactoryMethod and AbstractFactory but the following code doesn't seem to fit anywhere. Can someone explain to me what the following pattern is or if it is an anti-pattern? interace PaymentGateway{ void makePayment(); } class PaypalPaymentGateway implements PaymentGateway { public void makePayment() { //some implementation } } class AuthorizeNetPaymentGateway implements PaymentGateway { public void makePayment() { //some implementation } } class

Applying Abstract Factory Design Pattern in C++

瘦欲@ 提交于 2019-12-25 03:07:40
问题 I have a program where user enters the operations of a plane. User can select as many operations (holding, straight, landing etc.) as s/he wants. User can calculate the necessary fuel intake with operation 5. I have decided to apply Abstract Factory Design Pattern to my code. Here is the current version of the code without pattern is applied: #include <iostream> #include <stdio.h> using namespace std; class FlyingMode { protected: float time, fuel_rate, start, end, pace, distance; float total

Java generics and design patterns: not parameterizing a reference to a generic type is always a bad thing?

混江龙づ霸主 提交于 2019-12-23 10:59:07
问题 this question is partially related to my last question. I have a generic class representing a collection of generic objects: public interface MyObject<N extends Number>{} public interface MyCollecion<N extends Number> { public foo(MyObject<N> obj) } In my design these collections of objects are constructed by a client class (let's call it CollectionBuilder) through an abstract class approach: public interface AbstractCollectionFactory { public abstract <N extends Number> MyCollection<MyObject

Java interfaces, the creator patterns and the “getInstance()” method or equivalent

限于喜欢 提交于 2019-12-23 10:29:13
问题 I would like to start off by mentioning that my problem stems from the fact that interfaces in Java do not allow static methods. There have been discussions about the reason for this on SO (here , for example). So lets not dwell on that. I am looking for a way for my interface to create an instance of itself (rather, its implementation) and return that. In spite of playing around with Singleton pattern, Factory and AbstractFactory patterns, I still cannot achieve my goal. To elaborate on what

Java interfaces, the creator patterns and the “getInstance()” method or equivalent

China☆狼群 提交于 2019-12-23 10:29:07
问题 I would like to start off by mentioning that my problem stems from the fact that interfaces in Java do not allow static methods. There have been discussions about the reason for this on SO (here , for example). So lets not dwell on that. I am looking for a way for my interface to create an instance of itself (rather, its implementation) and return that. In spite of playing around with Singleton pattern, Factory and AbstractFactory patterns, I still cannot achieve my goal. To elaborate on what

When linking, is there something between “grab what you need” and “grab all” (-Wl,--whole-archive)?

南笙酒味 提交于 2019-12-22 06:48:29
问题 I have this library which involves some static initialization code which needs to run before main() . It all works well if you just compile all of the translation units together, but it doesn't work if I provide a static library ( .a file) and have users link their application against it - the linker simply ignores the symbols which do my static initialization. Alternatively, I can make the linker pick up everything in the static library, if I specify the -Wl,--whole-archive option to GCC, i

How to implement an [GoF]-ish Abstract Factory Pattern using an IoC like Ninject

时光总嘲笑我的痴心妄想 提交于 2019-12-18 07:06:32
问题 Abstract When the design requires an "Abstract Factory Pattern" like stated by the [GoF] including several products and over some product families, then setting up an IoC can become a bit tricky. Especially when the specific factory implementations need to be dispatched by runtime parameters and shared among some subsequent components. Given the follwing API, i was trying to set up my IoC (Ninject in this case) to retrieve Configuration objects configured through a IConfigurationFactory . The

What are the real benefits of using the Abstract Factory in the following example, instead of the factory method?

为君一笑 提交于 2019-12-17 17:22:07
问题 Before writing the question I read the following references: Factory Method Vs Abstract Factory Abstract Factory vs Factory Method (scope) Abstract Factory, Factory Method, Builder Factory, Abstract Factory and Factory Method Differences between Abstract Factory Pattern and Factory Method I see that many like me have had difficulty "grasping" the concrete differences between Abstract Factory and Factory Pattern. I'm not familiar with the design patterns, I came across this example http://www

What is the basic difference between the Factory and Abstract Factory Design Patterns? [closed]

可紊 提交于 2019-12-17 02:07:33
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . What is the basic difference between the Factory and Abstract Factory Patterns? 回答1: With the Factory pattern, you produce instances of implementations ( Apple , Banana , Cherry , etc.) of a particular interface -- say, IFruit . With the Abstract Factory pattern, you provide a way