design-patterns

What is the method MemberwiseClone() doing?

Basically, I am confuse with Developer devCopy = (Developer)dev.Clone(); Clone method of Developer class just creating a Employee clone, then how developer get another clone of developer. public abstract class Employee { public abstract Employee Clone(); public string Name { get; set; } public string Role { get; set; } } ...

What's a useful pattern for waiting for all threads to finish?

I have a scenario where I will have to kick off a ton of threads (possibly up to a 100), then wait for them to finish, then perform a task (on yet another thread). What is an accepted pattern for doing this type of work? Is it simply .Join? Or is there a higher level of abstraction nowadays? Using .NET 2.0 with VS2008. ...

Pattern to model wiki-type functionality

Is there a pattern or a gem (Ruby on rails) for modeling the wiki-like behaviour of a StackOverflow like web site? I'm working on Ruby-on-Rails project so a gem or something in RoR would be appreciated but a well defined pattern is just as good. Thanks ...

Pattern / Framework for lazy population of a database from remote source

My application pulls a large amount of data from an external source - normally across the internet - and stores it locally on the application server. Currently, as a user starts a new project we aggressively try to pull the data from the external source based on the order that we predict the user will want to access it. This process ca...

Builders in Java versus C++?

In Google's Protocol Buffer API for Java, they use these nice Builders that create an object (see here): Person john = Person.newBuilder() .setId(1234) .setName("John Doe") .setEmail("[email protected]") .addPhone( Person.PhoneNumber.newBuilder() .setNumber("555-4321") .setType(Person.PhoneType.HOM...

Factory or service pattern or method injection?

Hi all, I am currently thinking about with what pattern I should solve the following issue. I've got an entity called IdentificationRequest. This entity is used to identify a Person by some criteria. public class IdentificationRequest { public IdentificationCriteria Criteria; public Person IdentifiedPerson; protected i...

How to allow iteration over a private collection but not modification?

If I have the following class member: private List<object> obs; and I want to allow traversal of this list as part of the class' interface, how would I do it? Making it public won't work because I don't want to allow the list to be modified directly. ...

Super to Subclass Converstion

I am trying to find a clever way to convert a super class into a subclass using python. Here is the situation: class Super(): anAttribute = '' class Sub(Super): anotherAttribute = '' I have a function which returns me a list of type Super which I need to convert to a Sub, modify slightly and pass on to the next portion of my ...

How is code managed before OOP?

The most common issue for non-OOP is: how to prevent conflict of function name when the project becomes extremely huge? For OOP we can simply put the functions into different classes,but what's the approach for procedure programming? ...

What's the best way to implement deletion of user objects where there are multiple viewers of the object?

Let's say I have a GUI with multiple types of viewers of user objects. For example, a tree view, a list view and a diagram view. The three views show the same objects. If a user deletes an object from one view, I would like to fire off an event to notify the other two views. I currently do this by exposing an event on the object itself. ...

How can I keep separation of concerns when using a grid in the presentation layer (esp. .NET)?

In a three-tier model (presentation-business-data access layers), I can consistently keep my lower layers agnostic of the upper layers. For example my data access layer never knows how it is presented or what busines rules are operated on it. My business rules are agnostic of how they're presented. But I must pray to Demeter for forgiv...

Design question in WPF .NET.

Event Management An event is an entity which can be triggered when specified condition is met. User creates an event giving following inputs: Event Name Event Type ( event can be categorized ) Based on event type there is a condition which user has to specify. This condition is a criterion for raising the event. Event has Notification...

span insertion logic help

I have a text like this "You are advised to grant access to these settings only if you are sure you want to allow this program to run automatically when your computer starts. Otherwise it is better to deny access." and i have 3 selections, 1. StartIndex = 8, Length = 16 // "advised to grant" 2. StartIndex = 16, Length = 33 //"to g...

python: dictionary dilemma: how to properly index objects based on an attribute

first, an example: given a bunch of Person objects with various attributes (name, ssn, phone, email address, credit card #, etc.) now imagine the following simple website: uses a person's email address as unique login name lets users edit their attributes (including their email address) if this website ha...

Design pattern for order sensitive calling

I'm designing a small directory synchronization engine that can take different kinds of sources and handle incremental synchronization. I have defined an interface for a DirectorySource that currently looks like this: public interface IDirectorySource { IEnumerable<IDirectoryEntry> GetChanges(IList<string> attributes, IChangeToken t...

best place in MVC for user expiration

I have an ASP.NET MVC web app which has a really basic subscription system on it. My question relates to where the best place is to implement the subscription end date. At the moment, the following code resides in the Site.master: if (Profile.expires < DateTime.Today) { FormsAuthentication.SignOut(); FormsAuthen...

Hidden post input, or get variable?

Let's say you're making a blog application, and you're trying to decide how to build the comment form for a particular post. Would you put the blog_post_id as a hidden form field in the comment form, or would you set the form action to post_comment?blog_post_id=<id> and then grab it from the GET variable instead? Why? My 2 cent...

Model inheritance, the Factory pattern, and self-parsing in Ruby-on-Rails

Hi all- I am working with a site that will be pulling down feeds from a lot of different sources, and then saving those streams into a common model, in this case a trait. An example of the code from within the FeedEntry class might be: feed = Feedzirra::Feed.fetch_and_parse(feed_url) add_entries(feed.entries) ... def self.add_entrie...

Design pattern frustrations

Hi, I am a developer having 4 years of .Net coding experience, And never cared much about design patterns in my carreer. Recently i have been called for an interview with one of the biggies in the IT, have done 5 rounds (problem solving, pair prograaming , logical reasoning, 2 rounds of tech interview) of interview and didnt offer a j...

How to Lazy Initialize Class

I'm implementing a framework and want to create a lazy load initialization for one of my classes. how to do this ? ...