design-patterns

Using pre-defined instances

Hello everybody A few problem about instances are that Equals method doesn't provide true if even they contain same values. So trying to override Equals method provide much more slower than reference equality. While i was thinking point of performance, i thought that it is stupidly to create 2 instance which is same but not same memory...

How should my model look like?

As I am further digging into MVVM and MVVM-light I recognized, that there is no MVVM-light provided base class for models. But from my understanding, messaging and raising notifications could also happen in a model. At least in communication between models I would find that messaging would come in very handy. So I just decided to deriv...

What patterns exist for translating data from one type to another?

I'm working on a project where I have to take data from one source and translate/tweak it so that it can be properly consumed by a different source, in this case, the database. I imagine this is a fairly common problem, and while I believe I'm off to a good start, I'm stuck as to how best to implement the middle part of the solution tha...

Try and catch block. Which solution is better.

It seemed a reasonable pattern for me to use: int.TryParse() and simple if, rather than: int.Parse() inside the try block. Till I found this sample in MS pattern & practices /// <summary> /// Update a setting value for our application. If the setting does not /// exist, then add the setting. /// </summary> /// ...

Beginners guide to creating a REST service API (including RESTful authentication)

I would like to create an API. I would like it to be a REST API. However, I don't know the first thing about creating an API. Especially one that involves authentication. I'm looking for a guide that can help me understand how and why I should build my API a certain way. ...

What to use besides enum for c#

So currently have an enumeration used on the status of an application. However, something feels off when using it against the ui. To many conversions between integer and string when populating drop downs. I could use an extension method or the type converter and continue to use the enum which will be helpful if an enum has multiple words...

Which design pattern to choose

Hi, i need a pointer i the right direction. I have been looking around and cant seem to find any design pattern (GoF) that will point me in the right direction. I am developing a small digital signage application prototype, where there is a simple server and an amount of player applications (displaying an image/video) connected to this ...

Calling COM from .NET, is it an example of Adapter pattern?

If I write a code that calls COM component from .NET, is it an example of Adapter pattern? ...

What's wrong with this singleton I created

I created a class which allows access to global access to a variable while only creating it once, essentially a singleton. However, it doesn't match any of the 'correct' ways to implement a singleton. I assume that it's not mentioned because there is something 'wrong' with it but I can't see any problem with it other then the lack of l...

How do I deal with the reentrant call pattern in WCF?

Imagine a duplex WCF service that contains a list of subscribers. At some point the service sends data to all subscribers, and some of them may immediately call into the service again. The ConcurrencyMode of the service is Single, so this call fails with an exception. I would like to avoid that exception and found two possible solutions...

command pattern - overwhelmed! too small is too big, and too big is too big.

Greetings, I am writing a short simple script, but has became too crowded. Stuff has to do quite a few things class Stuff attr_accessor :config # stores configuration attr_accessor :dbh # stores database handle attr_accessor :logger # general logger to use def command_do_job_1 end def command_do_job_2 end def com...

Encapsulating a service call within an domain object method

Is this a valid object design ? I have a domain object where i inject a service and call a verify method to update the state of the object and if all goes well send a confirmation message. The code looks like: class Foo { String bar Service emailService public boolean verify() { bar = "foo" if(this.save()) { ...

How do i cache my business objects to avoid round trips to the database?

I have got myself saddled with an existing application - which attempts do do a lot of things by itself and does most of it badly! This application is an ASP.net 3.5 Web application having the typical UI -> Business --> DAL kind of pattern. The problem i am faced with is the fact that when multiple users are requesting the same informa...

How to make my programming designs better?

I'm currently stuck how I should make designing skills as a programmer better. I've seen over a dozen questions about (algorithmic) programming challenges. Defining and verifying a good design isn't as trivial. You can objectively measure how good an algorithm is, but not the design used to implement that algorithm. I do see problems wi...

Writing an class/struct that changes frequently

Summary: I have a struct that is read/written to file. This struct changes frequently, and this causes my read() function to get complex. I need to find a good way to handle change while keeping the bug count low. Optimally, code should be make it easy for one to spot the changes between versions. I have thought through a couple of pa...

MVC Pattern - Bind event listeners from controller onto views elements?

How do you bind an event listener from the controller to the view's elements eg button (click event) to its own handler? Originally I was doing this from the view eg. button.addEventListener(MouseEvent.CLICK, controller.buttonClick); But now realise this is wrong since reading "each view is only supposed to "know" about the model wh...

Design Patterns used in the jQuery library

jQuery is highly focused on the DOM and provides a nice abstraction around it. In doing so, it makes use of various well known design patterns which just hit me yesterday. One obvious example would be the Decorator pattern. The jQuery object provides new and additional functionality around a regular DOM object. For example, the DOM has...

signals and slots vs. events and event listeners

Straight to the point! How do signals/slots and event/event-listeners compare? Are there any pros and cons? Which one should I consider and why? Thanks in advance! ...

What's the design pattern name for using domain models & view models (aka AutoMapper) with MVC

Is there a name for the software design pattern that involves MVC with domain models and view models? It's the pattern used when a tool like AutoMapper is employed. I was attempting to explain the advantages of such a design to some fellow programmers and was calling it MVVM but I'm now of the opinion that's not right and the MVVM patte...

Domain object properties and encapsulation

I have an Email object with two properties, label and value. System user need to verify their email before they can use it in the system. The verification process is very simple: Set an activation code for the email Send an email with the activation code to verify that the email is valid The email object looks like the following: ...