Every so often, I run into a case where I want a collection of classes all to possess similar logic. For example, maybe I want both a Bird and an Airplane to be able to Fly(). If you're thinking "strategy pattern", I would agree, but even with strategy, it's sometimes impossible to avoid duplicating code.
For example, let's say the foll...
Hey all-
So I'm trying to figure out best practices on my database connection. I have a large .NET GUI that serves as the front end for the MySQL db. Currently I open a connection on application load and use it for whatever interactions I need. However, the entire GUI is single-threaded.
As I start to add BackgroundWorkers for large...
Say I have a basic interface like the following:
public interface IObjectProvider
{
IEnumerable<IObject> GetObjects();
}
The object source is some backing store that might be updated, and the implementation of this interface takes care of using that backing store. Now I'd like consumers of this interface to be able to take actions...
I am trying to design an HR leave application system. I need to know how best I can try to implement the following requirement in the front-end, as well as how to persist data in the db so that I can handle validations dynamically. Here is a small example of how we'd go about validating whether the employee is eligible for a leave.
Sup...
I'm writing a program where each component has an inheritance structure has three levels... ui, logic, and data... where each of these levels has an interface of defined functionality that all components must implement. Each of these levels also has some functionality that could be written generically for the whole interface, rather tha...
Besides textbook examples -- in the real world -- does it ever make sense to use multiple inheritance (where more than one of the base classes are not pure interfaces) in C++?
...
I need to create objects by reading their description from a text file.
The objects are also in a hierarchy or can be decorative objects
For example
For this descrition in a text file:
Sample.txt
A FileReader "fileName.txt"
A Buffered FileInput reader "FileName.txt"
A Buffered StringInput reader "TestString"
The program should ...
Guys,
I have a question, is this the correct approach to make a Generic Singleton?
public class Singleton<T> where T : class, new()
{
private static T instance = null;
private Singleton() { }
public static T Instancia
{
get
{
if (instance == null)
...
This is how I understand I can implement the singleton pattern in C#:
public class ChesneyHawkes{
private static ChesneyHawkes _instance = new ChesneyHawkes();
public ChesneyHawkes Instance {get{return _instance;}}
private ChesneyHawkes()
{
}
}
What if I want to provide a single instance of an object, so that the...
I have a generic repository that I communicate with my object context with. My object context has function imports that I want to be able to call through my generic repository. Currently I call them through an "Execute" function, but this is not ideal because I have to pass in my function name and parameters as strings which can cause r...
I am trying to follow the Nerd Dinner MVC application as a base to learn the correct way to develop MVC applications.
I have created Interfaces and Repositories as the reference code suggests and am using Entity Framework for data access.
If I want to insert data when a user registers into a table [dbo].[Users], I do not have a control...
Does the Android platform lend itself well to a particular style of UI programming like MVC or MVP? Most of my UI experience is with spaghetti code on a very old embedded device or in GWT with MVP so I do not know where to start.
...
I just started experimenting with a new technique I name (for the moment at least) "module duck typing".
Example:
Main Module
import somepackage.req ## module required by all others
import abc
import Xyz
Module abc
__all__=[]
def getBus():
""" Locates the `req` for this application """
for mod_name in sys.modules:
...
hey, hi i want put limit on object creation means a class can have at most suppose 4 objects not more than that how to achieve this?
...
Why do we need design patterns like Factory, Abstract Factory and Singleton?
...
Perhaps I have been doing Flex development with Frameworks like Cairngorm too long but I still don’t get MVVM. I am aware that Cairngorm is a framework and MVVM is a design pattern, but what I am comparing here is Cairngorms implementations of design patterns, mainly the model view controller and the command pattern. Don’t get me wrong,...
My application communicates with a large number of wcf services i.e. my application has several assemblies which each consume a different wcf service.
I am looking for a good wcf client design pattern so that I can keep my code concise, reusuable and elegant.
The wcf services which I consume are all the same - the basically used to che...
I'm refactoring a website I build. It's a website for a travel agency. I'm thinking of implementing the repository pattern.
The travel agency has two divisions, that have their own website and target different groups of customers. The backend however is the same for both websites. They both access the same DB tables. Some tables simply ...
I have a database that communicates with webservices with my Model (own thread) and exposes Data Objects. My UI application consists of different Views and ViewModels and Custom Controls. I'm using ServiceProvider (IServiceProvider) to access the Model and route the events to the UI thread.
Communication between the ViewModels is handel...
I am tasked to maintain and update a library which allows a computer to send commands at a hardware device and then receive its response. Currently the code is setup in such a way that every single possible command the device can receive is sent via its own function. Code repetition is everywhere; a DRY advocate's worst nightmare.
Obvio...