design-patterns

C# OO design problem with override from methods

Situation: Assembly 1 ________________________ ________________________ | Class A | | Class B | |-----------------------| |-----------------------| | Method someMethod |---------->| Method otherMethod | | | | | |_____...

OOP best practice: Employee.GetCars() vs Cars.GetByEmployee()

Given the classes Company, Employee, and Car what is the preferred practice for methods to retrieve Cars associated with Company or Employee? Employee.GetCars(params...) Company.GetCars(params...) Or: Cars.GetByEmployee(params...) Cars.GetByCompany(params...) The first approach is the one I have generally used and always seemed the...

NHibernate: Multiple Entities, One Transaction - Multiple Repositories?

I'm developing a web service using NHibernate, WCF and Oracle 11g R1. The web service is pretty simple: it maps DTOs to POCOs and performs various CRUD operations on them based on the operation called. Each entity has its own set of CRUD methods - this is a temporary, but necessary for the time being. I'm looking for input on a good R...

When to persist your business entities in your services classes

I have a method in my service where I create some entities, inside the method I call my repository's Add method so that the entities are persisted when I call my save method, should I call my Save method outside the service class or inside the method where I add the entities to the datacontext? ...

exception for notifying that subclass should implement a method in python

Hi! suppose I want to create an abstract class in python with some methods to be implemented by subclasses. (in Python) for example: class Base(): def f(self): print "Hello." self.g() print "Bye!" class A(Base): def g(self): print "I am A" class B(Base): def g(self): print "I am B...

when do we need Decorator Pattern?

when do we need to go for Decorator pattern? If possible give me a real world example that suits that pattern... ...

How can I refactor/extend the following model

I currently have a cache implementation (using arrays) for the heavy computations performed during the simulation. The structure of the cache is as follows: The way it works: CalculationsAbstract calculationsCache = new CalculationsCache(); // Constructor of CalculationsCache public CalculationsCache() { this.Proxy = new Calculat...

when do we need Adapter pattern?

When do we need to go for Adapter pattern? If possible give me a real world example that suits that pattern... ...

Seeking advice on js library for building a dynamic form generator.

Hi- Today, I'm building a little form generator for my firm. It would ask for someone to Add a Field, choose the field type (text field, checkbox, etc), name it and then add another and another if they want. I'd like to achieve this without having to go server side for each element. In other words, I want to take this opportunity to b...

Best way to deal with conflated business and presentation code?

Hi all, Considering a hypothetical situation where an old, legacy presentation library has been maintained over the years, and has gradually had more and more business logic coded into it through a process of hasty corrections and lack of proper architectural oversight. Alternatively, consider a business class or namespace that is not s...

Need some feedback on how to make a class "thread-safe".

I'm currently learning how to do multithreading in C++. One of my learning projects is a Tetris game. In this project I have a Game class that contains all game state data. It has methods for moving the block around and a few other things. This object will be accessed by the user (who will use the arrow keys to move the block, from the m...

Repository pattern and/or/vs business logic layer

I have a problem I want to know your opinion. I am trying to use Repository Pattern. I have a repository object which load data to a POCO. I have also created a Business logic layer which adds a little bit of functionality but basically wraps the POCO. So in the end I have a BLL which loads DAO with usage of repository. I am not very h...

Tree Data Structure OOP Design Problem (C#)

Hi Guys, I have a tree structure design problem, and i can't think of a way out. i want to have one class Tree containing a generic data, and extend the Tree class with ComplexTree that will contain more methods like Iterate, DoSomthingOnComplex, etc. here is a sample of the code i have: class Tree<TData> { public TData Data { ge...

How to handle collection with the Domain Model ?

Hi, I implemented the domain model from the book Zend Framework: Survive the deep end but nowhere they mentions how to handle collections of objects. I mean, how to find multiple rows ? Similar to fetchAll() ? Any advises, best practices to work with such things ? ...

What is the correct C# design pattern for multiple methods, all accepting as params differing derived classes?

Hi, I have a base class: class Message And two deriving classes: class SimpleMessage : Message class ComplexMesssage : Message These types are used in another part of the code as such: void ProcessSimpleMessage(SimpleMessage m) void ProcessComplexMessage(ComplexMessage m) These methods are not inside the class Message, as the p...

Is Repository pattern as same as Active Record pattern?

They seems to be similar. ...

making a SingletonMixin class in c++

Hi guys: I have four classes, let's call S1, S2, S3 and S4. These class are singletons; each one have a getInstance and a finalize method - and an instance private variable-. Now, to avoid repeting the finalize and getInstance methods I'm trying to make a SingletonMixin class, something like: template<class T> class SingletonMixin { ...

Design, storage and retrieval of dynamic forms

What is the design behind custom dynamically generated forms? Would like to implement something like drupal's CCK. In the control panel, the owner of the form designs what fields should be in the form and in what order the form fields should be in, as well as the field's attributes such as "required: yes/no" Once the form has been de...

using base classes on other class constructor C#

I'm trying to understand the observer pattern using C#, first I have an abstract class working as Subject called Stock, then I'm creating a concreteSubject class so I'm going to call it IBM, as the concreteSubject Class is going to inherit from Stock, so I do something like this: class IBM : Stock { // Constructor public IBM(str...

Creating the same model from multiple data sources

This is mostly of a design pattern question. I have one type of model that I'm going to get the data to create them from multiple sources. So for example one record my be created from an API where another is created via screen scraping with Nokogiri. My issue lies in how best to abstract out these different data sources. Right now I...