lundi 22 février 2016

Design patterns for analysing a combination of instances?

I'm looking for a recommendation on a design pattern which could be used to interpret an array of different Object instances. Ideally, these pattern definitions would be statically defined.

So, as an example, I'm looking for something along the lines of this:

Ingredient [] lIngredients = new Ingredient []{ new Lime (), new Soda (), new Sugar (), new Mint (), new Rum () };

Patterns.WHITE_RUSSIAN.isRecipe(lIngredients);//returns false Patterns.MOJITO.isRecipe(lIngredients);//returns true

I managed to develop a working solution using Object class references, however it's clear that later on in my development some of my patterns will rely upon instance data members, whilst others will not. I'd like the patterns to be flexible, so they may not have to depend on a specific ordering in the array, or ignore superfluous elements.

Are there any widely-used approaches that suit these requirements?

Aucun commentaire:

Enregistrer un commentaire