design-patterns

What are the list of Patterns and Principals the programmer must/should know?

I have been doing code for a few years and still feeling that my knowledge still not broad enough to become a professional. I have studied some books related to Design Pattern but I know there are many others. So could anyone list the one which you think it is good to learn to become a better programmer and more professional? Programm...

How do I make my Linq to Sql entity expose an interface?

Using Nerd Dinner as an example: private NerdDinnerDataContext db = new NerdDinnerDataContext(); public IQueryable<Dinner> FindAllDinners() { return db.Dinners; } Is it not bad practice to directly expose the entity class Dinner here? I think it is better for the repository to return an IDinner. So my question is, how can I mak...

Is Abstract Factory Pattern implemented correctly for given scenario.... ???

First thing... I am novice to pattern world, so correct me if wrong anywhere Scenario: There are multiple companies providing multiple products of diff size so there are 3 entities i.e. Companies, Their Product and size of product I have implement Abstract Pattern on this i.e. so that I will create instance of IProductFactory interfac...

PHP Design Pattern Advise

Hi there, I have two years worth of PHP experience however I have never worked with design patterns. I have recently been given a task at work that has made me question the wisdom of that decision. I have been asked to create a system that: Insert orders into a database. These orders can have a multitude of attributes and control l...

Design Question - how do you break the dependency between classes using an interface?

Hello, I apologize in advance but this will be a long question. I'm stuck. I am trying to learn unit testing, C#, and design patterns - all at once. (Maybe that's my problem.) As such I am reading the Art of Unit Testing (Osherove), and Clean Code (Martin), and Head First Design Patterns (O'Reilly). I am just now beginning to unde...

Regarding the ViewModel

Im struggling to understand the ViewModel part of the MVVM pattern. My current approach is to have a class, with no logic whatsoever (important), except that it implements INotifyPropertyChanged. The class is just a collection of properties, a struct if you like, describing an as small part of the data as possible. I consider this my Mod...

Do you know Best Practise and Design Patterns for Adobe Air/Flex Applications?

I'm going to write an application with the Air/Flex-Framework. I'm looking for Best Practise and general Design Patterns for designing software especially in Air/Flex. I have experience with this framework but never had the pleasure to write a piece of software from scratch. For instance: I stumbled across lots of software written in ...

Would you rather use a Singleton or dispatch another class' event through a Chain of Responsibility?

In general, what would make your program more maintainable? I know a lot of folks that make heavy use of Singletons, but that seems like a cop-out, which creates a kind of global junk drawer organization. ...

Process a batch of items, return an object to report on status

I'm looking for a pattern (or good practice) for the following scenario: My function List<BatchItemResponse> Process(List<BatchItem> Data) {..} will process a list of data, and return info on where each item in the batch could be processed. struct BatchItemResponse { int BatchItemID; bool Processed; string Description; } Any thoughts...

I'd want a method to be called only by objects of a specific class

Suppose you have this class: public class A { private int number; public setNumber(int n){ number = n; } } I'd like the method setNumber could be called only by objects of a specific class. Does it make sense? I know it is not possible, is it? Which are the design alternatives? Some well known design pattern? So...

Add multiple entities to Javascript namespace from different files

Given a namespaces ns used in two different files: abc.js ns = ns || (function () { foo = function() { ... }; return { abc : foo }; }()); def.js // is this correct? ns = ns || {} ns.def = ns.def || (function () { defoo = function () { ... }; return { deFoo: defoo }; }()); Is this the proper way to a...

OOPS and ADO.Net

Hi, I am building an bugtracking application where I am thinkining of taking maximum possible benefits of OOPS starting from my presentation layer to my data access layer. The architecture will be as usual 3-tier but I want to use Design Patterns or simply OOPS to create connection pull out data or something like that. ...

What is the difference between the Facade and Adapter Pattern?

I've been reading both definitions and they seem quite the same. Could anyone point out what are their differences? Thanks ...

Which design pattern is most appropriate?

Hello, I want to create a class that can use one of four algorithms (and the algorithm to use is only known at run-time). I was thinking that the Strategy design pattern sounds appropriate, but my problem is that each algorithm requires slightly different parameters. Would it be a bad design to use strategy, but pass in the relevant par...

What exactly is GRASP's Controller about?

What is the idea behind Grasp's Controller pattern? My current interpretation is that sometimes you want to achieve something that needs to use a couple of classes but none of those classes could or has access to the information needed to do it, so you create a new class that does the job, having references to all the needed classes(thi...

What do I name this class whose sole purpose is to report failure?

In our system, we have a number of classes whose construction must happen asynchronously. We wrap the construction process in another class that derives from an IConstructor class: class IConstructor { public: virtual void Update() = 0; virtual Status GetStatus() = 0; virtual int GetLastError() = 0; }; Ther...

Inject different repository depending on a querystring / derive controller and inject the repository depending on the controller type / ASP.NET MVC

I have a search form that can search in different provider. I started out by having a base controller public SearchController : Controller { protected readonly ISearchService _searchService public SearchController(ISearchService searchService) { _searchService= searchService; } public ActionResult Search(....

Limit number of parameters per method?

Assuming the parameters are all the same type, is there a rule of thumb in regards to the number of parameters for a method? Im just wondering where I should draw the line and what my alternatives are (ie interface, array, etc). ...

Implementing the procducer-consumer pattern with .NET 4.0

With alle the new paralell programming features in .NET 4.0, what would be a a simple and fast way to implement the producer-consumer pattern (where at least one thread is producing/enqueuing task items and another thread executes/dequeues these tasks). Can we benfit from all these new APIs? What is your preferred implementation of this ...

Can I use the decorator pattern to wrap a method body?

I have a bunch of methods with varying signatures. These methods interact with a fragile data connection, so we often use a helper class to perform retries/reconnects, etc. Like so: MyHelper.PerformCall( () => { doStuffWithData(parameters...) }); And this works fine, but it can make the code a little cluttery. What I would prefer t...