design-patterns

Factory Pattern in C++ — doing this correctly?

百般思念 提交于 2020-01-21 01:36:32
问题 I am relatively new to "design patterns" as they are referred to in a formal sense. I've not been a professional for very long, so I'm pretty new to this. We've got a pure virtual interface base class. This interface class is obviously to provide the definition of what functionality its derived children are supposed to do. The current use and situation in the software dictates what type of derived child we want to use, so I recommended creating a wrapper that will communicate which type of

Trying to understand the event aggregator pattern

心不动则不痛 提交于 2020-01-20 21:44:06
问题 I am trying to implement the event aggregator pattern in a simple way to learn it step by step. But i didn't find any book or nice video tutorial talking about it's implementation. I just found some good articles such as this http://weblogs.asp.net/rashid/archive/2009/03/05/use-event-aggregator-to-make-your-application-more-extensible.aspx and http://martinfowler.com/eaaDev/EventAggregator.html the first article is too big to let me understand the pattern and the second one is not completed :

Differences between Proxy and Decorator Pattern

こ雲淡風輕ζ 提交于 2020-01-19 06:28:25
问题 Can you give any good explanation what is the difference between Proxy and Decorator ? The main difference I see is that when we assume that Proxy uses composition and Decorator uses aggregation then it seems to be clear that by using multiple (one or more) Decorators you can modify/ add functionalities to pre-existing instance (decorate), whereas Proxy has own inner instance of proxied class and delegates to it adding some additional features (proxy behaviour). The question is - Does Proxy

Using a class' __new__ method as a Factory: __init__ gets called twice

拈花ヽ惹草 提交于 2020-01-19 04:46:27
问题 I encountered a strange bug in python where using the __new__ method of a class as a factory would lead to the __init__ method of the instantiated class to be called twice. The idea was originally to use the __new__ method of the mother class to return a specific instance of one of her children depending on the parameters that are passed, without having to declare a factory function outside of the class. I know that using a factory function would be the best design-pattern to use here, but

Refactoring legacy mixin-based class hierarchies

一曲冷凌霜 提交于 2020-01-19 04:04:05
问题 I'm currently working on a huge javascript project which has a huge class hierarchy and heavily uses mixins to extend functionality of base classes. Here is an example of how mixin looks like, we're using compose library to create class-like objects: // Base.js var Base = compose({ setX: function (x) { this.x = x; }, setY: function (y) { this.y = y; }, setPosition: function (x, y) { this.setX(x); this.setY(y); } }) // SameXAndY.js - mixin var SameXAndY = compose({ // Executes after setX in

Naming Classes - How to avoid calling everything a “<WhatEver>Manager”? [closed]

倾然丶 夕夏残阳落幕 提交于 2020-01-18 04:31:07
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . A long time ago I have read an article (I believe a blog entry) which put me on the "right" track on naming objects: Be very very

state design pattern

独自空忆成欢 提交于 2020-01-17 15:54:48
问题 I am trying to implement the state pattern but the problem is, that I am not changing the states and when I use a test class it is using the concrete class that has a relationship with the interface. For example in the fire and move methods in the state classes are not working and returning the result of the Railgun. Here is the code: public interface RailgunState { public String fire(Point p, int rounds); public String move(Point p); } public class Railgun { /** * @param ammo repersent the

state design pattern

杀马特。学长 韩版系。学妹 提交于 2020-01-17 15:52:22
问题 I am trying to implement the state pattern but the problem is, that I am not changing the states and when I use a test class it is using the concrete class that has a relationship with the interface. For example in the fire and move methods in the state classes are not working and returning the result of the Railgun. Here is the code: public interface RailgunState { public String fire(Point p, int rounds); public String move(Point p); } public class Railgun { /** * @param ammo repersent the

PHP MVC: Multiple databases, multiple data mappers?

风流意气都作罢 提交于 2020-01-17 13:57:14
问题 I am working on my HMVC project. Right now I am using data mappers in order to move data between the models (domain objects) and a MySQL database. Each mapper receives a MySQL adapter as dependency. The injected adapter receives a PDO instance (a database connection) as dependency and runs sql queries on the database. I also use a dependency injection container (Auryn). I'd like to be able to simultaneously retrieve data from storages of different types (MySQL database, PostgreSQL database,

PHP MVC: Multiple databases, multiple data mappers?

落爺英雄遲暮 提交于 2020-01-17 13:57:10
问题 I am working on my HMVC project. Right now I am using data mappers in order to move data between the models (domain objects) and a MySQL database. Each mapper receives a MySQL adapter as dependency. The injected adapter receives a PDO instance (a database connection) as dependency and runs sql queries on the database. I also use a dependency injection container (Auryn). I'd like to be able to simultaneously retrieve data from storages of different types (MySQL database, PostgreSQL database,