i made a state machine and would like it to take advantage of generics in java. currently i dont see the way i can make this work and get pretty looking code. im sure this design problem has been approached many times before, and im looking for some input. heres a rough outline.
class State { ... }
only one copy of each distinct st...
I think the problem is pretty common. You have some input string, and have to call a function depending on the content of the string. Something like a switch() for strings.
Think of command line options.
Currently I am using:
using std::string;
void Myclass::dispatch(string cmd, string args) {
if (cmd == "foo")
cmd_foo(arg...
I'm writing a little webapp for mobile.
There is a form asking for a particular item and its details, users should be able to insert one or more items with their details.
If it was a normal webapp I'd use ajax with a link "add one" just like gmail does for attachments. On mobile I think it's not a good idea using ajax, so I used "i'm d...
Hi,
It is very common to create Dependency Injection container for the ASP.NET application so it lives while the application lives.
I create the DI container in each request and release it at the end of the request.
The main purpose is that any DI container supports Disposing objects when the container gets disposed.
Additional: ...
Warning: This is super in-depth. I understand if you don't even want to read this, this is mostly for me to sort out my thought process.
Okay, so here's what I'm trying to do. I've got these objects:
When you click on one (or select several) it should display their properties on the right (as shown). When you edit said properties it ...
I am trying to make a function f that works like this:
StorageObject::addItem (const AbstractBase& base) {
AbstractBase* storage = new Derived1(base);
}
However, I would like f to work with classes Derived2, Derived3 etc as well. Is there a way to get f to call the correct constructor depending on the specific subclass of Abstract...
Consider the following PHP snippet:
<?php
class Is
{
function __get($key)
{
$class = __CLASS__ . '_' . $key;
if (class_exists($class) === true)
{
return $this->$key = new $class();
}
return false;
}
function Domain($string)
{
if (preg_match('~^[0-9a-z\-]{1,63}\.[a-z]{2,6}$~i', ...
As a matter of best practice in MVC, where should the logic go that deals with things such as password hashing/salting or data formatting before it gets sent to the database? I've read that the repository should only be used for logic that deals with data access. Is this something that belongs in a service layer? The controller? Does it ...
Had a code smell moment and couldn't decided if its OK for a class to be Observable and also an Observer, so thought I'd post here.
class ObservableAndObserver extends Observable implements Observer {
// Class is ofcourse registering and receving notifcations on different events
// effectly actving as a middle man.
// Is this a pa...
Suppose there are different groups of scientists (Medical) serving emergency tickets.
When an emergency ticket arrives for the common pool (group), at any time only one scientist is allowed to pick up the ticket , while others can or will be notified automatically that this particular guy is working on the ticket.
note : A single guy c...
Here is the scenario:
I have a visual that displays some data
The data to the visual can come in one of two ways
Via user input through the keyboard or mouse
Via some backend source
Both these data inputs can be of one of two forms
Control data or
Raw data for simple display
Control data causes changes in the visual
Raw data is sim...
I am trying to make a C++ implementation of the board game Carcassonne. I am trying to make a tile object which has four sides and one of three basic terrains(field, road, city).
The best interface for tile creation I could think of was of the form:
City city;
city_city_city_city = new Tile(city, city, city, city);
Where a Tile clas...
Hi there,
When using a Service Locator class to serve up ViewModels for your WPF pages to bind to. Should the ViewModels be Singleton scoped or Factory scoped? Is one generally a better idea for WPF applications??
I'm aware that in Silverlight, Singleton lends itself better to pages which are User Controls and are only moved into and o...
need to use a good PHP ORM that has elements of Datamapper and i am not clever enough to code it myself.
chosen doctrine, but after reading through the user guide, cannot find anything that says how to use identity map to lower calls to database.
please show me how to have identity map in doctrine ORM?
just read and understood stuff ...
I have the convenient object factory template that creates objects by their type id names. The implementation is pretty obvious: ObjectFactory contains the map from std::string to object creator function. Then all objects to be created shall be registered in this factory.
I use the following macro to do that:
#define REGISTER_CLASS(cla...
Greetings fellow overflowers,
After reading on MSDN about correct strategies on how to perform database replication, and understanding their suggestion on Master-Subordinate Incremental Replication. It left me wondering, what OOD design pattern should I use on this...
The main elements of this strategy are the Acquirer, the Manipulator...
Hi,
We are designing a product which could support multiple databases. We are doing something like this currently so that our code supports MSSQL as well as MySQL.
namespace Handlers
{
public class BaseHandler
{
protected string connectionString;
protected string providerName;
protected BaseHandler()
...
When I was learning to code, I read up on the design patterns like a good boy. Long after this, I started to actually understand them.
Design discussions such as those on this site constantly try to make the rules more and more general, which is good. But there is a line, over which it becomes over-analysis starts to feed off itself an...
As described in the motivation of using the Abstract Factory, i need an interface which i want to be highly flexible, i.e, it should have a number of possible behaviors. So, following the AF design pattern, I define an abstract class with the interface functions as follows:
class WidgetFactory{
...
public:
CreateScrollBar();
...
An application I'm working on requires logging of actions, user who performs the action, and time of action to a database.
Which design pattern is most popular/appropriate for logging?
I'm thinking of Command pattern that require the current user and an action. Perform the action and write to the log.
What do you think? Any other ...