design-patterns

In C++ how to best decouple 2 classes that must maintain collections of references to each other

南楼画角 提交于 2020-01-23 19:32:09
问题 I am looking for advice on the most elegant and secure way to decouple two C++ classes that maintain collections of pointers to each other's types. I implemented it recently using a common base class for polymorphism and was told that it was an unsatisfactory solution. I am eager to learn other ways this can be achieved. Thanks in advance... I have added a simplified version of the class definitions below. I am aware that the SalesTeam class is not decoupled from SalesPerson here. // Global

PHP MVC: Query builder class for Data Mapper layer

做~自己de王妃 提交于 2020-01-23 16:59:12
问题 I'm working on my own MVC framework in PHP. Its model layer consists of Domain objects (also known as "models"), which encapsulate the business logic and Data mappers, for transfering the data between the domain objects and the database. A data mapper abstract class does not exist, each data mapper class containing its own implementation of the data access layer. The class methods of the data mappers contain, or will contain complex sql statements. My question is : Under these circumstances,

MVC design convention: CRUDing inherited models [closed]

醉酒当歌 提交于 2020-01-23 12:50:07
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . Here's my database structure: In my app I have a company management of customers, employees and branches. Customers and Employees are associated with one

MVC design convention: CRUDing inherited models [closed]

时光毁灭记忆、已成空白 提交于 2020-01-23 12:49:16
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . Here's my database structure: In my app I have a company management of customers, employees and branches. Customers and Employees are associated with one

Python: Passing SequenceMatcher in difflib an “autojunk=False” flag yields error

早过忘川 提交于 2020-01-23 10:51:10
问题 I am trying to use the SequenceMatcher method in Python's difflib package to identify string similarity. I have experienced strange behavior with the method, though, and I believe my problem may be related to the package's "junk" filter, a problem described in detail here. Suffice it to say that I thought I could fix my problem by passing an autojunk flag to my SequenceMatcher in the way described by the difflib documentation: import difflib def matches(s1, s2): s = difflib.SequenceMatcher

Hiding multiple implementations behind a single interface

╄→гoц情女王★ 提交于 2020-01-23 08:10:46
问题 I know about the Strategy and Abstract Factory design patterns - however they don't solve my current problem: I'm creating a C++ library that offers a very basic GUI. However I want the user to be able to choose at compile time which GUI library to use (say Qt or FLTK) to actually render the GUI. The user should however only need to know about the methods in my library. It should be possible to compile the same code without any changes using either a Qt backend or an FLTK backend. I thought

Hiding multiple implementations behind a single interface

孤街醉人 提交于 2020-01-23 08:10:05
问题 I know about the Strategy and Abstract Factory design patterns - however they don't solve my current problem: I'm creating a C++ library that offers a very basic GUI. However I want the user to be able to choose at compile time which GUI library to use (say Qt or FLTK) to actually render the GUI. The user should however only need to know about the methods in my library. It should be possible to compile the same code without any changes using either a Qt backend or an FLTK backend. I thought

When “if else”/“instance of” are inevitable, how do we improve the design apart from using visitor pattern?

偶尔善良 提交于 2020-01-23 07:07:52
问题 When we have an object hierarchy that is purely a inheritance of semantic and not of behaviors,then inevitably we need to write "instanceof" or "if/else" everywhere to do run time type checking. E.g. If I have a object hierarchy which has Class Function Class Average extends Function Class Sum extends Function Class Max extends Function If there is a method called calculate() in these classes, then we do not have problem, we can just take the advantage of polymorphism and this design

How to change this design to avoid a downcast?

我们两清 提交于 2020-01-23 02:05:08
问题 Let's say I have a collection of objects that all inherit from a base class. Something like... abstract public class Animal { } public class Dog :Animal { } class Monkey : Animal { } Now, we need to feed these animals, but they are not allowed to know how to feed themselves. If they could, the answer would be straightforward: foreach( Animal a in myAnimals ) { a.feed(); } However, they can't know how to feed themselves, so we want to do something like this: class Program { static void Main

Dependency Injection Container - Factory Pattern

[亡魂溺海] 提交于 2020-01-22 19:48:11
问题 I have been trying to learn about dependency injection and have been reading about and trying to code a small dependency injection container similar to this: http://fabien.potencier.org/article/12/do-you-need-a-dependency-injection-container The one thing that is confusing me is this: Isnt a dependency injection container just a glorified implementation of the factory pattern? If so, why not just call it that, why the need for a fancy term only to confuse matters. If it isnt, can someone