design-patterns

Passing a type at runtime to FirstOrDefault

I have this common code: private bool DoItStartup(IReader reader, Type provider) { /// lots of common boiler plate code /// like: var abcProvider = reader.ReaderData as AbcProvider; var xyzProvider = abcProvider.Provisions.FirstOrDefault<XyzProvider>(); // line 2 } The above lines of code are there for like 50 or some provi...

What is composition as it relates to object oriented design?

I hear (and read on this site) a lot about "favour composition over inheritance". But what is Compositon? I understand inheritance from the point of Person : Mammal : Animal, but I can't really see the definition of Compostion anywhere.. Can somebody fill me in? ...

C++ Techniques For Newbies

Hi all, Is there any good list of techniques + descriptions for C++ newbies. I was thinking of a list describing RAII, RVO, Lvalues... This would be for newbies that don't currently understand those techniques or come from other languages where those are not applicable. Something short & sweet would be preferred :-) ...

C++ singleton template class

Hi, In a recent project I had to create a Singleton class and after a lot of digging around on Google I came up with this template class definition. The idea is to derive from this template class and make the derived class' constructor protected / private. It seems to work well but I have only used it with a single class in one project ...

Strongly-typed integers

As a thought experiment on a hobby project, I've been thinking of a way to ensure that this sort of subtle bug/typo doesn’t happen: public void MyMethod(int useCaseId) { // Do something with the useCaseId } public void SomeOtherMethod() { int userId = 12; int useCaseId = 15; MyMethod(userId); // Ooops! Used the wrong va...

Best design pattern for "undo" feature

Possible Duplicate: Design Pattern for Undo Engine In general, how do you deal with supporting an "undo" feature in your application? I have worked on web apps and desktop apps alike, and I have never really felt comfortable with any "undo" system I've made. ...

Why most DataContract's DataMember I read from many coding websites is not written with automatic property?

As an example from this site: http://www.c-sharpcorner.com/UploadFile/ankithakur/ExceptionHandlingWCF12282007072617AM/ExceptionHandlingWCF.aspx [DataContract] public class MyFaultException { private string _reason; [DataMember] public string Reason { get { return _reason; } set { _reason = value; } }...

What is the best way to cleanly structure PHP sites without using a framework?

I'm working on a medium sized PHP site. I'm writing "provider" classes for my objects. Basically, if I have a "user" object, I have a "user-provider" class that can request / save users on the database, accepting and returning user objects. I just include the providers and the dependent objects in the files I need them. I'm wondering if...

Does my repository have too much logic?

I have a legacy database that my new application has to interact with. The old database is over-normalized and poorly designed in general. For instance, one object in my domain represents five tables in the database. I want to keep my domain layer free of artifacts from the legacy database. What pattern should I use here? At first glanc...

several instances of singleton class

Hello all I have some class it is a singleton we have this class in already several applications and it is used there as a singleton. Now i am writing some new application and i need several instances of that class , what is a best practice to have sevaral instances of it ? By deriving from it and making the private constructur to be ...

Anybody have a clever way to treat a DTO as more of an OO class?

I have a set of DataContracts that are serialzed through WCF. Please note this is a very simplified example. [DataContract] public class MyData { [DataMember] public List<int> MyList { get; set; } } I would like to use object oriented design so that the server and client aren't creating any unnecessary...

an instance hot-swapping itself with a new instance

I have some actions... View, Edit, Checkout, etc. Business logic dictates that if a document is already checked out, all Views turn into Edits. is there a neat OO way to do something like this: class Action { public: Document document; virtual void execute(); }; class View, Edit, Checkout : public Action; View::execute() { if (d...

ASP.NET Email Patterns

ASP.NET Webforms application. Problem: How to implement emailling elegantly? Many parts of the application demand it. This will include HTML emails, solutions how to handle bouncebacks etc.. I have the option to use my own SMTP server (app is hosted on a VPS), or to use the hosting providers. I'd like to start logging here too (lo...

Design pattern name: Is it a factory?

The following class shows something similar to a real use case. It returns always the same instance for the same thread. public class LookingForName { private static final ThreadLocal<Something> threadLocal = new ThreadLocal<Something>(){ @Override protected Something initialValue() { ...

Design Patterns: Do you use them in your projects?

How do you decide on which design pattern to choose for? My approach to development projects has always been. Take down business requirement. Design the database. Decide on technology (This decision is almost always driven by the client.) Start developing a prototype. Get prototype approved. (iterative) Build the application. Release ...

I'm in an anti-pattern and I want to get out.

I am developing a java webapp, using jsp/jquery/ejb/jboss. I have a web-form that enables the user to select any combination of 100 fields (all from different unrelated tables/objects) from the database. These fields are then output, via a java servlet, to an excel spreadsheet. A stored procedure is executed that always returns all 100 ...

Factory pattern and class templates in C++

I have a hierarchy of class templates. At the top of the hierarchy is an abstract base class (interface). I won't know which concrete implementation to instantiate until runtime, so it seems like the perfect situation to use the factory pattern. However, virtual member function templates are not allowed in C++. How can I achieve a le...

programming language with granular method and property access

Hi, imagine something like this: import class B.*; interface A supports A.testSum { int sum( int a , int b ) access from B.calculator; testSum() { Assert(sum(1,1)==2); } ........ class B ... { void calculator() { A.sum(3,5); //ok } void someOtherMethod() { A.sum(0,3); //compile error } the idea of the "supports" is s...

GUI: Decoupled view and design patterns for RIA

I made some GUI desktop applications on my first years of development, but my experience and practice have changed, so now I'd like to retake this subject with better knowledge. Most of my experience has been web since then. I've been reading about GUI Architectures, and several related questions here on S.O.. I know I'm still not in ...

Flex: How to keep code away from MXML

Can you recommend articles,books and best practices on designing Flex applications? (both AIR and web). I've read Creating components and enforcing separation of concerns with Flex and Building components by using code behind. Does the application always have to start on the Main MXML? Can't I instantiate the first view from an Action...