design-patterns

Head First's Design Patterns

Is Head First's Design Patterns book suitable for someone with an intermediate knowledge of C++ and no knowledge whatsoever of Java? Thanks. ...

What Design Pattern to use?

The problem to model is this: A hierarchy of levels within an Army, starting with the national army in whole, through field armies, subunits, and eventually the individual men. Each level may involve links to one or more other classes such as General or Officer or whatever. The units within say a field army need to be able to communicat...

How should I design a method that allows for optional operations?

For example, suppose I this: class Gundam00 extends Gundam implements MobileSuit { ... public void fight(final List<MobileSuit> mobiruSuitso, final List<Gundam> theOtherDudes, final List<Person> casualities) { .... } } Suppose theOtherDudes and casualities parameters are optional. How can I make this method as cle...

What is this design pattern used in Enumerator.?

I've seen this pattern in Enumerator. It makes sure the collection haven't been altered while enumerating over the items. public class Versioned { internal int version = 0; public void ThisBreaksVersion() { version++; } } public class WorksOnVersioned { private readonly int version; private readonly Ver...

Which and all design patterns & Classes can be used for Copy-Paste Operation ?

Which and all design patterns & Classes can be used for Copy-Paste Operation ? ...

Sharing content between business objects and DTOs

All, My typical approach for a medium sized WCF service would be something like: Define the interface using WCF data contracts and service operations. The data contracts would be POCO DTOs with no CRUD or domain logic. Model the domain using fully featured business objects. Provide some mechanism to go from DTO to BO and vice versa (...

Where did variable = null as "object destroying" come from?

Working on a number of legacy systems written in various versions of .NET, across many different companies, I keep finding examples of the following pattern: public void FooBar() { object foo = null; object bar = null; try { foo = new object(); bar = new object(); // Code which throws exception. ...

Generic solution to simple classes + factory

My tiny mind can't come up with an elegant solution to this problem. Suppose I have class such as this: public class Foo<T> { public RecordType Type { get; set; } public T Value { get; set; } } Where RecordType may look something like this: public enum RecordType { EmptyRecord, Boolea...

Abstract Base Class vs. Concrete Class as a SuperType

After reading the most excellent book "Head First Design Patterns", I began proselytizing to my colleagues the benefits of patterns and design principles. While extolling the virtues of my favorite pattern - Strategy Pattern - I was asked a question which gave me pause. Strategy, of course, uses inheritance and composition and I was on...

C++ state design pattern with multiple state machines

Hi, I have a C++ state machine implemented using the State design pattern. Each state is implemented as a nested friend class of the context class. class Context { public: /* The Context class' user calls process1() to get it to perform an action */ void process1(); private: class IState; void switchState( IState *newState ); ...

Managing updates to nested immutable data structures in functional languages

I've noticed while on my quest to lean functional programming that there are cases when parameter lists start to become excessive when using nested immutable data structures. This is because when making an update to an object state, you need to update all the parent nodes in the data structure as well. Note that here I take "update" to m...

How to deal with null value in <select> HTML filter ?

I have an user interface that print user, and I wan't to have a filter by country. I made a classic <select /> element. In JSP I have <select id="country" onchange="return filter();"> <option value="">...</option> <c:forEach var="country" items="${countries}"> <option value="${country.id}" ${country.name} ...

How can I use decorators to implement my PHP Form class?

I am developing a Form class in PHP responsible for displaying and validating an HTML form. I know generally what the Decorator design pattern is, and I know Zend_Form uses the pattern extensively to provide easy customization to its output of the form. I have looked through the source for Zend_Form, and cannot make heads or tails of h...

When to refactor to a design-pattern?

When coding and reviewing code, it's easy to spot places where a design pattern could be used. A chain of command here, a strategy there... It's tempting to dive in and apply patterns even though a better solution might be a switch or some simple if's. Are there some rules or tips you've found valuable to estimate when to do the actual ...

Is there a better/cleaner way to conditionally create a type than using instanceof? [Java]

Suppose I have: public class FightingZone<MobileSuitso, Background> { private MobileSuitCollection<MobileSuitso> msCollection; private BackgroundInfo<Background> bgInfo; public FightingZone(MobileSuitCollection<MobileSuitso> newCollection, BackgroundInfo<Background> newInfo) { this.msCollection = newCollection; ...

Interface declaration for base class method to support IoC

So here is the code: interface A<T> { T Save(); } interface B : A<B> { } class BusinessBase<T> { T Save(); } class D<T, U> : BusinessBase<T> where T : BusinessBase<T> where U : B<U> { new U Save() { base.Save(); // this is where the error is because T can't be converted to U } } class Concrete : D...

Is Dependency Injection a pattern and, is this it?

I was having a heated debate with one of my colleagues on dependency injection, and realized I didn't quite know all the facts on the subject. So, take this code (just so you know,we're using Castle Windsor) IPlayerService service = Container.Resolve<IPlayerService>(); The above code is obviously an example of DI using an IoC. Howev...

Questions about common patterns in WCF, in a layerd architecture

We're about to set off our first larger WCF project, and we're having some concerns on how to layer our application correctly and where all the patterns go. The services will primarily be consumed by applications on the Intranet, and secondly by customers over the Internet. Our idea was to layer the application this way, inspired by DD...

Looking for recommended reading material on developing modular CMS's

I am trying to find suitable reading material in the form of published books, online articles and guides which cover topics on good design principals for CMS's. I am looking to add support to an open source PHP framework I am involved with to aid others in the development of modular systems including CMS and additionally the development...

How should I require different fields on the same object when returned from different methods?

I will have multiple WCF component methods returning a common object. In some cases, fields A,B,C,D will be required to be non-null, but in other cases fields B,F,G,Q may be required to be non-null. I want to indicate to whoever may be creating these methods which fields are required for any particular method. I'd also like to enfor...