design-patterns

How to sort this Repository pattern and ASP.Net website architecture ?

I am Creating a new ASP.Net website "not mvc", and willing to make the data access layer has 2 versions, one using the Linq to Sql and another one using ad.net entity framework. Note: kigg is doing the same but in MVC website and too complex than i want. I learned that the best pattern to achieve my goal is using repository design patter...

Persisting Enums as byte or text to database

I am not able to make a clear decision on this one. I am OK by having numeric values on my tables and have the value information on the description of the column on the database for DBA. But I also don't want to come to a point in future where having these numeric values on database creating too much headache for maintenance. I'm not...

Problems with Singleton Pattern

I've been reading about Singleton pattern for last few days. The general perception is that the scenarios where it is required are quite few (if not rare) probably because it has its own set of problems such as In a garbage collection environment it can be an issue with regards to memory management. In a multithreaded environment it ca...

best way to design aggregate model that can be lazy loaded

Hi All, I have to construct a simple viewer page of a model let us assume Person, where i present a set of criterias to the user to choose from(based on state of persisted models) for e.g i have a dropdown for departments showing all the distinct departments for which Person records are available and once departments are chosen , i wi...

refactoring and removing case statements when circling over an enum structure

Hello, An enum structure declared in its own class is a member variable to the business logic class. That enum basically represents the state of that other class. Although I have revisited the issue several times, replacing, or getting rid of those case statements proves quite frustrating to me. Several business logic methods simple i...

Need advice on implementing UI in WPF

Hi, I need some advice on implementing UIs in WPF. So far, I've been using Code-Behinds, which is extremely easy to get-started, but hell when maintaining/changing/testing. I've looked at MVP (and its WPF variant - MVVM), but having some trouble getting started. Assuming I have a UI to build, here's what I think I should do: 1. Crea...

linking methods from an enum to member variables of client class

Hello, The following enum structure performs certain operations while remaining agnostic to the client class (for encapsulation reasons) public enum MyEnum implements Commands{ A{ public int method1(int varY) { return varY+2; } public MyEnum method2(){ return MyEnum.B; ...

[C++] How do I implement a "single instance"-like design?

Hi, I'm writing an application which will run as a daemon. UIs will connect to it over TCP. Now, there is a class called UiTcpInterface which will handle all communication between the UI and this daemon. Now, I'm faced with the problem of ensuring there is only one instance of UiTcpInterface. What would be the best way to do it? Curren...

About code quality and designing

Hello, I don't know if I am only like this or maybe some people has same problem. Always when I get a project I don't know how to design it well. I mean I just try to make UML design, but always it doesn't show the final result. In the end project has so many changes which aren't in the design, so my drawn UML gets useless to people who...

tagging methods and calling them from a client object by tag

Hello, I have been trying to figure out a way to tag several methods from my base class, so that a client class can call them by tag. The example code is: public class Base { public void method1(){ ..change state of base class } public void method2(){ ..change state of base class } public void m...

When to include helper methods in a model (MVC)?

I think the easiest way to ask this question is with the actual real-world situation I'm facing. In our system, we have a Site model (classic MVC framework here) that represents a row in our site table. One of the fields of the site table that is stored in the Site model is the time zone of the site. We use this to adjust UTC datetimes ...

How do I create a builder in C# for an object that has properties that are referenc types?

I've started to construct a builder so that I can easily create test data for unit tests I am writing. The basic structure of the builder is: public class MyClassBuilder { public int id = 0; //setting the default value here //allows MyClass to be built with a specific id public MyClassBuilder WithId(int id) { t...

[C++] How to solve the problem of global access?

Hi, I'm building an app, and I need the wisdom of the SO community on a design issue. In my application, there needs to be EXACTLY one instance of the class UiConnectionList, UiReader and UiNotifier. Now, I have figured two ways to do this: Method 1: Each file has a global instance of that class in the header file itself. Method 2:...

What is the best way to initialize an application?

What is the best way of initializing and terminating an application? The library needs to be initialized/terminated only once and can be used by any number of dlls. Is there any standard design to accomplish this? This initialization has to be the very first step. Is singleton is what I need here. Any number of dlls which are loaded...

Design problem with nearly static data

I am developing an interpreter of a simple programming language. There are tree-structured dynamic data, where each of the data nodes has an associated (owned) type-object. There are several kinds of the types - ListType, StructType etc. - and one special - TypeRef. The TypeRef holds a name (a string) which refers to some concrete type...

Mutual notification patterns

Propose to consider the following problem. Suppose we have some composite object. Are there patterns that describe the solution of mutual notification of composite object parts, when states of these parts are changed ...

Generic Identity Map in C#. Don't want public constructor.

I'm trying to implement an identity map using generics. I have an abstract class, Entity, and a derivation constraint on my map for Entity. Since my map needs to be able to instantiate entities, my map also has a constructor constraint. However, for the map to be useful, Entity subclasses should not be able to be instantiated from clien...

Does C# include finite state machines?

I've recently read about the boost::statechart library (finite state machines) and I loved the concept. Does C# have a similar mechanism ? Or can it be implemented using a specific design pattern? ...

Availability Issue

Architecture: A bunch of clients send out messages to a server which is behind a VIP. Obviously this server poses an availability risk. The client monitors a resource and the server is responsible to take action based on the what status the majority of the clients report to it and hence the need for only 1 server/leader. I am thinking...

How to persist Strategy Pattern (behavoir) with LINQ 2 SQL?

I am designing an app that will be using LINQ2SQL to persist the data in a database. I often use the Strategy pattern. For instance, I may have a ClubMember object which can use different cost strategies like the following: class ClubMember { public String name { get; set; } public String email { get; set; } private IMembe...