design-patterns

Domain driven design pattern clarification

Hi all Im trying to build a solution using a DDD approach. Ive created a set of entities, and some datamappers i use to remove the data persistence dependency from the entities. Is it correct of me, to use a datamapper like a "finder" class, i have methods like getById() getUsersByRanking() getByLastName() or should the datamapper ...

What typical pattern(s) are used for a system that integrates data from many sources with non standard apis?

I've never asked anything this general before, and I'm not sure if it's going to sound like I'm asking for someone to do my work for me. I'm an experienced programmer but I'm somewhat new to the kinds of design patterns that get talked about on sites like this. Synopsis of parameters: (1) There are 3 external systems that are effective...

If I am not allowed to use the Singleton pattern, what are the options?

Possible Duplicate: What's Alternative to Singleton If I am not allowed to use the Singleton pattern because it is not good OOP, what are my options? I often have a lot of stuff that needs quick access. If I use a Singleton I am told it is not good OOP, and if I reference the stuff I get a lot of classes with to much reference...

How to handle 'this' reference in decorator pattern

I have a problem in a class of mine that uses the decorator pattern. The problem arises when the inner object uses the "this" reference in calls to other objects. This causes all calls from the object that received the "this" reference to be made directly to the inner object, without going through the outer first. What is the usual wa...

Const and non-const access resolves to different overloads?

Let me say we have a simple programming task. But for the sake of clarity I start with few code samples. First of all we written a some kind of data container class but for the purposes of task no matter what the class is. We just need it to behave const-correct. class DataComponent { public: const std::string& getCaption() const { ...

Global variables between files in Node.js?

Here are 2 files: // main.js require('./modules'); console.log(name); // prints "foobar" // module.js name = "foobar"; When I don't have "var" it works. But when I have: // module.js var name = "foobar"; name will be undefined in main.js. I have heard that global variables are bad and you better use "var" before the references. B...

Design pattern for class interaction

I'm having some trouble deciding how two classes should interact and the problem I'm having seems like it would come up a lot so I was wondering if anyone knows of a design pattern (or any kind of solution) that addresses my issue. Basically I have two classes. Class A deals with displaying information to the user and Class B deals with...

C# object creator

In javascript, I often use something like this object creator var o = new Object(); // generic object var props = { color:"red",value:5 }; // hashtable for(var key in props) o[key] = props[key]; alert(o.color); //red Can it be written as C# method with this declaration? static void properties(out Object o, HashTable h) { .....

A Singleton that is not globally accessible

I just wondered what the best way is to get rid of the globally available static getInstance() in a Singleton. I do not want my Singleton classes being accessed from every point in my program. I thought about maybe having a create() public static function that creates one object and returns it but one cannot call this method twice. But...

How to intentionally cause a compile-time error on template instantiation

Sometimes when coding with C++ templates, you want to prevent users from instantiating a specific specialization or set of specializations, because the result would be nonsensical. So you can define a (specific or partial) specialization whose definition, if instantiated, would cause a compiler error. The goal would be, if a user "misu...

Is MVC simply a concept or is there more to it?

I'm learning about MVC and am wondering if there is more to it other than the concept of view->control->model? What is ASP.NET's MVC, is it again just the method of splitting front end, processing and data up - as with the general idea of MVC? ...

Composite pattern in Swing

This is basically a architectural question. I want to implement composite pattern in handling Swing components; that is, I want to combine several components with their listeners and logic behind a single component for easier handling. Consider for example a simple directory browser; say, a JTree in JScrollPane with some logic which ha...

What is the best way expose key classes/methods my core API to 3rd party developers?

I have an application that I have designed and this app has a pretty decent core dll that contains an API that my main view's exe uses. I would like to allow other developers to access this core dll as well but I don't want them to have as much access as me since it would be a security risk. What is the standard way of exposing my core...

GoF explanation of the Decorator Pattern is confusing (or just plain wrong)

I'm going over some design pattern questions and I looked at the definition and examples of the Decorator Pattern in GoF. It says Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. It gives examples of Decorators which use inheritance w...

Object generator pattern

I have a class that represents a pretty complex object. The objects can be created by many ways: incremental building, by parsing text strings in different formats and by analyzing binary files. So far my strategy was as follows: Have the constructor (__init__, in my case) initialize all the internal variables to None Supply different ...

Why are CRUD operations so bad in a SOA design?

I have just finished reading an article on MSDN by John Evdemon. He bashes the CRUD interfaces and calls it an anti-pattern. While I agree that having ANYTHING stateful is difficult and Current and MoveNext are bad ideas I don't agree that CRUD as in Create Read Update and Delete are bad. If I have a car service and I want to let client...

Builder Pattern in Ruby with YAML

I have an instance of the Builder pattern in my project right now. Currently, the supported output format is CSV, however I would now like to include YAML. Easy, I thought. I have all of the supporting code in to make the type change. I'm finding myself to be in a bit of a complex. The intent of using the Builder pattern was to construc...

Multiple discrimination levels while using Doctrine2

I'm using Doctrine2 to manage my model below: There's an abstract concept Content with a Composite pattern in Gallery, also an abstract concept Media from which Video and Image inherits. My choice was to add discriminators to Content and Media tables in order to differentiate between Gallery, Video and Image. Content uses JOIN inherit...

Is it better to generate html for an ajax function in the JS handler or in the PHP ajax function?

I'm designing some UI's for a product and we want to utilize jQuery and PHP. The content to generate is a list of checkboxes (10-100) that a user will be modifying (removing multiple at a time and changing the entries). I thought I'd try something new and ask StackOverflow (read: you) what is preferred: generate the html in the php call ...

ASP.NET MVC singleton or static class to pass around data?

I'm creating a controller that will serve the combined/minified versions of my JavaScript and CSS. I need to somewhere along the line define which scripts/styles to be loaded. When a request is made, for example for style.css?VersionNumberHere, it will check if the combined/minified data is already in the HttpContext.Cache, if so spit i...