design-patterns

Abstract Factory design pattern to create objects? Why can’t we just use the new operator?

why do we need a Abstract Factory design pattern to create objects? Why can’t we just use the new operator? answer is, to avoid tight coupleing of the objects. But I didn't understand how ? can anyone explain with code (will be very useful). what makes abstract factory design pattern useful and when. Thanks in advance. Harsha T ...

Database Abstraction & Factory Methods

I'm interested in learning more about design practices in PHP for Database Abstraction & Factory methods. For background, my site is a common-interest social networking community currently in beta mode. Currently, I've started moving my old code for object retrieval to factory methods. However, I do feel like I'm limiting myself by ke...

Why use singleton instead of static class?

When would a singleton actually be easier or better than a static class? It seems to me creating a singleton is just extra effort that's not actually needed, but I'm sure there is a good reason. Otherwise, they wouldn't be used, obviously. ...

Generic multi-layer data access pattern?

I've been playing around with some new patterns for n-layer data access, and came across one that seems very flexible and easy to implement. Basically, I needed a solution that could make various data layers pluggable/swapabale on the fly - i.e., base data access from DB, distributed caching, local caching, etc. The code below is easily...

What would be the best way to implement a constant object?

First of all I should probably say that the term 'constant object' is probably not quite right and might already mean something completely different from what I am thinking of, but it is the best term I can think of to describe what I am talking about. So basically I am designing an application and I have come across something that seem...

Design Patterns and Prinicples

I have recently experienced and understood the importance of "Design Patterns and Principles" implemented in our project. I was just wondering if you all would share the importance of Design patterns and principles, of how using them in your source code the project was enhanced, so that we can learn out of your vast programming experienc...

How to convert/translate informations?

I have to "translate" codes with a conversion table like this: | symbol | translation | | 1 | 3 | | 2 | 4 | | 3 | 6 | | 4 | 5 | | 5 | 2 | | 6 | 1 | | 7 | 1 | My first idea was to use a Map associating each symbol to its translat...

.net design pattern question

Hi. I am trying to understand design pattern problems. I am trying to modify the code like this in winforms and trying to see if any design pattern suits my requirement. Please suggest which is the best design pattern in this scenario. This is very basic code containing 2 tab pages which might have different controls can be added dynami...

Is passing a repository interface to a domain level service clean?

Background: Our app is a fairly straight forward MVC web app that calls a service layer. That layer uses a unit-of-work pattern to access some repositories then pass those objects to a domain level service to perform some logic. It's very clean and works well for us. Issue: We now have a case where we get a large chunk of xml from a ...

Java, Design pattern : Multiple event sources and One event Handler

Hello everybody, I want to implement a design in Java where I have multiple event sources (Threads). Such event source accomplish a specific task and had to notify the unique Event Handler (Class) and this one have to accomplish other tasks according to event sources notifications. My question is : how to implement this desiqn in the a...

Practical rules for premature optimization

It seems that the phrase "Premature Optimization" is the buzz-word of the day. For some reason, iphone programmers in particular seem to think of avoiding premature optimization as a pro-active goal, rather than the natural result of simply avoiding distraction. The problem is, the term is beginning to be applied more and more to cases...

Reusability, testability, code complexity reduction and showing-off-ability programming importance

There are lots of programming and architecture patterns. Patterns allow to make code cleaner, reusable, maintainable, more testable & at last (but not at least) to feel the follower a real cool developer. How do you rank these considerations? What does appeal you most when you decide to apply pattern? I wonder how many times code reu...

Application wide messaging... without singletons?

So, I want to go for a more Singleton - less design in the future. However, there seem to be a lot of tasks in an application that can't be done in meaningful way without singletons. I call them "application wide services", but they also fall into the same category as the cross cutting concerns, which I usually fix via AOP. Lets take a...

Is the a pattern for iterating over lists held by a class (dynamicly typed OO languages)

If I have a class that holds one or several lists, is it better to allow other classes to fetch those lists (with a getter)? Or to implement a doXyzList/eachXyzList type method for that list, passing a function and call that function on each element of the list contained by that object? I wrote a program that did a ton of this and I hat...

Asynchronous request management application design

I have a daemon which exposes RMI interface for submission of various potentially long running bulk operations. The daemon may also talk to workflow/BPM system as a part of request processing. This essentially means that the request processing (post submission) also has an asynchronous component to deal with; which probably would require...

Unsure how to come up with a good design

Hello there, I am having trouble coming up with a good design for a group of classes and was hoping that someone could give me some guidance on best practices. I have kept the classes and member functions generic to make the problem simpler. Essentially, I have three classes (lets call them A, B, and C) as follows: class A { public: ...

How to proxy calls to the instance of an object

Edit: Changed question title from "Does C# allow method overloading, PHP style (__call)?" - figured out it doesn't have much to do with actual question. Also edited question text. What I want to accomplish is to proxy calls to a an instance of an object methods, so I could log calls to any of its methods. Right now, I have code similar...

Does this pattern have a name?

Disclaimer: I'm trying to learn proper OO programming/design, so I'm pretty new to this stuff. I guess this is a general design patterns question, but I'll base my example on a game engine or something that renders objects to the display. Consider the following: How can this sort of separation between physical objects (e.g., cubes,...

Factory Pattern: Determining concrete factory class instantiation?

I'm trying to learn patterns and I'm stuck on determining how or where a Factory Pattern determines what class to instanciate. If I have a Application that calls the factory and sends it, say, an xml config file to determine what type of action to take, where does that logic for interpreting the config file happen? THE FACTORY using S...

Should services include logged in user as a parameter?

Hi, When using the Service design pattern, do you usually place the logged in user, or user scope, as a parameter to the methods of the service interface, or do you call AutheticationService.getLoggedInUser() in the service implementation. What advantages/disadvantages do you find for each option? ...