design-patterns

ASP.net MVC: Where in my design should I create/declare entity keys?

When creating a new entity object that has a foreign key value I need to create a new Entity key (Entity Framework in .net 3.5) for the object, but I'm having trouble deciding where in my application I should do this. Right now when I create a new record with a foreign key, I create the entity key in the controller (in this case a user ...

Which Design Pattern to use for MS Surface Apps (WPF)?

Background: I'm currently for my University creating some simple apps showcasing the possible educational potential of the Microsoft Surface. Their functionality falls somewhere between a basic demo app and a full-fledged production app. Our hesitation with using MVVM or some other type of MVC is that, with the exception for the few a...

Converting enum into a class hierarchy

Let's say I am writing a class in Cocoa to act as a proxy to a server. To represent the current state of the connection, consider the enumeration: enum { MyConnectionStatusDisconnected = 0, MyConnectionStatusConnecting, MyConnectionStatusConnected, MyConnectionStatusCount }; typedef NSUInteger MyConnectionStatus; I may...

Is it bad practice to make a setter return "this"?

Is it a good or bad idea to make setters in java return "this"? public Employee setName(String name){ this.name = name; return this; } This pattern can be useful because then you can chain setters like this: list.add(new Employee().setName("Jack Sparrow").setId(1).setFoo("bacon!")); instead of this: Employee e = new Employee...

State Pattern: How the states of an object should transition when they're involved in complex processes?

Guys, I have some doubts about the following implementation of the state pattern: I have an Order object. For simplicity, let's suppose it has a quantity, productId, price and supplier. Also, there are a set of known states in wich the order can transition: state a: order is new, quantity must be > 0 and must have productId. Price an...

Cancel pattern for background thread

I have code running in a background thread that need to periodically check if the user wants to abort the work. The question is how to implement this in a mostly SOLID environment. An ICancel interface that I inject into every class. A public static member somewhere Non-const statics seem to always create problems sooner or later. O...

PHP Data Access to Multiple Records

So currently I am using a pattern to grab a data entry (record). It works great for me if I only need to work with one record. However if more than one record is involved it gets more complicated. Here is my base pattern, using a contacts table: class Contacts_Entry { private $_entry = Array('contact_id' => false, ...

Is there an optimized .net implementation of design patterns?

I have seen .net optimized implementation of design patterns on http://www.dofactory.com. But not all patterns are available on the site. Is there a site/blog which has an .NET optimized implementations of all design patterns? ...

Find a Book About Practical approach to learn RUP

Hi everybody, I want to learn RUP but don't find a practical book!. I read the "Guide to the Unified Process featuring UML, Java and Design Patterns" by John Hunt But this book is so brief. is there a book that learns the RUP step by step with UML diagram(each discipline)? tnx. ...

Adapter Design Patter | adapter that converts an Iterator to an Enumeration |ConcurrentModificationException

As part of an exercise, am implementing an ArrayList which will support Enumerations. Following is the adapter that converts an Iterator to an Enumeration: public class MyEnumeratorAdapter<Object> implements Enumeration<Object> { private Iterator<Object> adaptee; public MyEnumeratorAdapter(Iterator<Object> it) { this.ada...

When is lazy evaluation not useful?

Delay execution is almost always a boon. But then there are cases when it’s a problem and you resort to “fetch” (in Nhibernate) to eager fetch it. Do you know practical situations when lazy evaluation can bite you back…? ...

Model the real world or the proper OOP world? Or both?

I'm writing a game where the mouse-driven controller object clicks on a player object to have it do something. There are 2 ways of initiating the interaction between mouse and player: Controller calls player's function: Controller listens for mouse events. When a mouse click occurs anywhere onscreen, the controller searches all obje...

How to design a C++ class?

I wrote a application in MFC with C++. I need to write a class which can save all the data loaded from the database, These data might contain every kind of data type, such as int, string, byte, boolean, datetime and so on. We might filter, exchange columns, or sort on these data. For example: int int string bool double float .... st...

Coding architectural question

Hi all, I'm after some guidance on how to approach coding a problem, I don't want to jump straight into coding without think about it as I need it to be as generic and customisable as possible, The scenario is i have a web service that acts as a gateway to downstream services, with the aim of authenticating and authorising SOAP messag...

Should I attempt to fix an arguably poor design decision in a 3rd party library?

My project involves Qt plus and unnamed 3rd party physics simulation library. The way the physics library works is that physical bodies cannot create themsleves; the "world" must instantiate them so that they can be added to the world immediately. My project creates a wrapper around these physical bodies to add some extra functionality,...

When not to use IoC and DI?

I see lots of articles saying how great IoC and DI are and none about why it isn't so great because it can make code more complex. I see also that IoC shouldn't be in the core part of your code but more for libraries and plug-ins. Articles usually a small reference to how the two patterns can make code more complicated but not much on t...

Repository Pattern Question

I'm building an ASP.NET MVC app and I'm using a repository to store and retrieve view objects. My question is, is it okay for the implementation of the various repositories to call each other? I.E. can the ICustomerRepository implementation call an implementation of IAddressRepository, or should it handle its own updates to the address d...

Best practices when limiting changes to specific fields with LINQ2SQL

I was reading Steven Sanderson's book Pro ASP.NET MVC Framework and he suggests using a repository pattern: public interface IProductsRepository { IQueryable<Product> Products { get; } void SaveProduct(Product product); } He accesses the products repository directly from his Controllers, but since I will have both a web page a...

How to deal with user authentication and wrongful modification in scripting languages?

I'm building a centralized desktop application using Python/wxPython. One of the requirements is User authentication, which I'm trying to implement using LDAP (although this is not mandatory). Users of the system will be mechanical and electrical engineers making budgets, and the biggest problem would be industrial espionage. Its a comm...

Is processing Javascript Server-Side a solution to duplicated logic?

Web-Applications these days make extensive use of Javascript, for example various Google Products like Gmail and Calendar. I'm struggling to how NOT having duplicated logic server and client side. When requesting a page or state of the application, i would prefer to send the complete UI, meaning: not just some javascript, which in turn...