I'm trying to do a small and simple GUI in C++ (with SDL). I'm experimenting with the Composite pattern to have a flexible solution.
I've got a Widget class, with Component objects : for instance, there is a PaintingComponent ; if I want to draw a box, I'll use a PaintingBoxComponent, that inherits from the PaintingComponent.
The ide...
I'm currently gathering all the possible information to build a new web application core.
I have built many different CMS'es before, but they have always turned out to be too weak for my requirements and to expand them, it takes too much time. Basicly, I want to build this "new" core, which would allow me to easily extend it with module...
In most modern OO languages chaining methods together is common, and IMHO elegant, practice. In jquery, for example, you often see code like:
$('div').addClass('container').css('color', 'white').length
Does writing your objects to allow this have a name?
...
I have such design:
public interface MyInterface {
public abstract List<Sth> getSth();
}
public class MyConcreteImplementation implements MyInterface {
private ConcreteSth mSth = new ConcreteSth();
public List<Sth> getSth(){
return mSth.getSth(additionalParams);
}
}
Purpose of code above is to provide unifie...
A entity with active record is a object or a component?
...
I have a Question class which has a property OptionList, which is nothing but a List. Questions and Options are stored in diff tables in the db.
Now there are times when I need just the Question object without its Relational Properties, that is properties which are entities mapping to a different table in the db. Thus in this case I do...
Q: The title is perhaps too big of question and the answer probably is "it depends"? However, providing some practical cases/examples should help developers, like myself, recognize when to apply what. I'll start out with my particular situation. Would you or would you not use custom error classes? Why/why not?
Other examples as the one...
I've seen some questions on this pattern but I am trying to understand more about this design pattern in depth. Any resources in this regard, experts commentary on what scenarios they tend to use this pattern and what scenarios to avoid and some real world examples will be really helpful in this regard. I am not looking for what is COR t...
What is the best way to destroy a singleton object?
case A: Single threaded Environment
case B: Multi Threaded Environment
Sample snippets(if any) will be really helpful.
[EDIT] I don't have a specific use case I am just trying to understand that IF AT ALL the singleton has to be used how to destroy it correctly. As i understand...
I have an Interface
interface IRepository<T>
{
List<T> GetAll(string id)
List<T> GetAll(string id, string desc)
List<T> GetAll(string id, string desc, int[] status)
List<T> GetAll(string id, string desc, int[] status, ....)
}
Many of my classes were implementing this interface. My problem is, more often, when cl...
For a fun project I'm trying to implement the BitTorrent spec, and right now I'm working on the BEncoding portion of it.
The encoding basically can encode from int/string/dictionary -> string for transmission. I've got all of the different encodings written/tested/working as overloaded Encode(...) methods and I've got the individual de...
Hi,
I have written a JAXB mapping that stored a sublist inside a root element in a LinkedHashMap<String, Object> instead of a Collection<Object> maintained through a specific XmlJavaTypeAdapter. Hereunder a sample:
@XmlRootElement
public class Parent {
@XmlJavaTypeAdapter(ListToMapAdapter.class)
@XmlElement
private LinkedHa...
Hi there,
I have been reading a little bit about the Module pattern and i wonder if applicable for what i need to do or should i use the Constructor/protoType pattern.
Basically I am using unobstrusive javascript so i have a reference to my .JS file in my HTML document.
If i understand it correctly then I can call a INIT method (which...
Greetings all:
I currently am building a web application, and have been debating whether to go with a conventional database login system, or going with an openid based login system as we have on stackoverflow and family. What my question is when would an application designer would choose an openid system over the more conventional login...
Hi,
I have to create a lot of objects which relate to each (i.e. one is passed in as a parameter of the constructor to the other) to do some work.
Usually factory type patterns seem suitable for making only one object. This is several. I was thinking of doing something like a fluent interface and then the properties on the class are th...
Let's say I have a package called 'animal' including Animal parent class, Cat extends from Animal, Dog extends from Animal, also. Animal, however, is designed like this:
class Animal {
int amount;
Animal next; // Then a constructor initializes these.
drinkWater(int n) { ... }
}
Cat & Dog classes follow this structure:
class Ca...
I'd like to create WPF control which consists of few another controls. The main problem is how implement choosing right control depending on Model's type?
<MyControl>
<!-- if DataContext.GetType() == Type1 -->
<Control1 DataContext = {Binding}/>
<!-- if DataContext.GetType() == Type2 -->
<Control2 DataContext = {Binding}>
</MyControl>
...
Take an example of a question/answer site with a 'browse' slideshow that will show one question/answer page at a time. The user clicks the 'next' button and a new question/answer is presented to him.
I need to decide which pages should be returned each time the user clicks 'next'. Some things I don't want and reasons why:
Showing ...
I am looking for a design pattern where it fits these specs:
1- Say you have a package animal including 'Animal', 'Cat' and 'Dog'.
2- You have to modify a method behaviour in 'Animal' (also overridden in 'Cat' and 'Dog' as in the package) without doing any modification in the package animal source code.
I did find Visitor Pattern for ...
What are the steps that you follow when approaching a problem statement, which needs to be converted in to a OO design. I do know the approach might be subjective depending on the problem and varying for each but I am sure there must be some basic generic steps that each good designer will follow while breaking down a problem statement i...