patterns

How would you balance between designing and (actually) implementing you application

My question is not programming language specific, but its more generic question to see the way of people thinking. Usually in Large development houses there are specific roles for each job, such as Programmers and architects. so architects point of view is to have a perfect architect and solution design, on the other hand programmers a...

Which pattern to use in replacement of composite with limited number of element type ?

Hi, I have an object can be compose by components but each components has a type and should be unique : Class Client{ Set<IComposite> elements } interface IComposite{ String getType(); } class Status implements IComposite{ String getType(){return "status"} } class ClientDates implements IComposite{ String getType(){return "c...

Creational Pattern: "Bastard Factory", a Abstract Factory spinoff

I am currently trying to figure out what the best way is to create my objects on my current PHP 5.2 project. I basicly have a Registry which returns objects by keys. If the Registry does not have an object with the specified key it will try to create one by calling a factory method that is supplied to the registry by construction. Look a...

C++ static template with external implementation

I have an a simple Registry pattern: class Object { //some secondary simple methods }; #define OBJECT_DEF(Name) \ public: \ static const char* Name() { return Name; } \ private: class Registry { struct string_less { bool operator() (const std::string& str1, const std::string& str2) { for(int i = 0; i < str1.size() && i < st...

Change syntax using regular expression

I have some inherited legacy language code snippets stored in a database table that I need to transform to a SQL like syntax so it can be used more effectively. For example, one of the snippets is of the form keyword = [a,b,c,x:y,d,e,f,p:q] to indicate either discrete comma separate values or a range of colon-delimited values How c...

Is it possible in c# to make a factory that merges interfaces?

var mergedInstance = MergeFactory<InterfaceOne, InterfaceTwo>(); ((InterfaceOne)mergedInstance).InterfaceOneMethod(); ((InterfaceTwo)mergedInstance).InterfaceTwoMethod(); Can anyone recommend a design pattern or exact syntax that would make something like this work? Inside the MergeFactory, I'm picturing something like this going on:...

Efficiency of design patterns

Hello, Does anyone know any sites/books/articles covering best practices or theory around design patterns in high performance applications? It seems a lot of the patterns use indirection/abstraction/encapsulation in a way that may affect performance in computationally intensive code. Head First Design Patterns and even GoF mention possi...

Registry pattern and lazy instantiation of registered objects

Hello, Let's imagine that we have Registry pattern... <?php class Registry { private static $objects = array(); private static $instance = null; public static function getInstance() { if (self::$instance == null) { self::$instance = new Registry(); } return self::$instance; } protected function _get($key)...

Optimization: How should i Optimize the Linq Concat of Collections? C#

is there any way i can Optimize this: public static IEnumerable<IEnumerable<int>> GenerateCombinedPatterns (IEnumerable<IEnumerable<int>> patterns1, IEnumerable<IEnumerable<int>> patterns2) { return patterns1 .Join(patterns2, p1key => 1, p2key => 1, (p1, p2) => p1.Concat(p2)) .Where(r => r.Sum() <= sto...

Are TDD and POAD Competing Methodologies?

Over the summer, I've been reading a lot about design. Two notable pieces that I read were Test Driven Development: By Example by Kent Beck, and another named Pattern-Oriented Analysis and Design: Composing Patterns to Design Software Systems by Yacoub. These books take two very different approaches to designing software systems. My imp...

when do we need Decorator Pattern?

when do we need to go for Decorator pattern? If possible give me a real world example that suits that pattern... ...

when do we need Adapter pattern?

When do we need to go for Adapter pattern? If possible give me a real world example that suits that pattern... ...

Any design patterns/coding methods for complex logic?

I had to clean up code for an online college application. There's nothing particularly wrong with it, but it was complicated. Different degree programs had different prequisites, fees, required documentation, and questions. On top of that, students coming from the military get different fees, and previous students pay no fees and skip...

Service References vs Assemblies References, using WCF Services

I have a WCF Service (with servicecontracts, datacontracts, etc) , like this: [ServiceContract(Namespace = "http://company.com/MyCompany.Services.MyProduct")] public interface IService { [OperationContract] CompositeType GetData(); } [DataContract(Namespace = "http://company.com/MyCompany.Services.MyProduct")] public class Comp...

Three state button in Silverlight

I have a button with 3 States Start/Resume/Pause. 1 Is this a good pattern to solve this or maybe there is some toggle button mode that I am not aware of? private void cmdStart_Click(object sender, RoutedEventArgs e) { if (m_end) { // Reset the game. m_end = false; cmdStart.Conten...

Making a class available only to a single other class

I have a C# project in which I use the Memento/Command pattern to implement Undo/Redo functionality. The application is a WPF application that uses StructureMap for IOC, has extensive unit tests and makes use of mocking via interfaces using RhinoMocks. In my code I have an Operation class which represents all undoable operations, and I ...

Question about prototype pattern

The objective of prototype pattern is to clone an object by reducing the cost of creation. Here is an example: class Complex { int[] nums = {1,2,3,4,5}; public Complex clone() { return new Complex();//this line create a new object, so is it violate the objective of prototype ?// } } class Test2 { Comp...

Which programming patterns would be appropriate for a ‘sea battle’-type game?

Hello! I want to improve knowledge of different programming patterns. I want to write a simple game. Which pattern would you suggest for a simple/casual game? edit: The game will be a "sea battle" type game, with simple AI and maybe later i'll add some networking to it. ...

Dissolve string bytes into a fixed length formula based pattern by using keys, and even extract those bytes.

Suppose there is a string containing 255 characters. And there is a fixed length assume 64-128 bytes a kind of byte pattern. I want to "dissolve" that string with 255 characters, byte by byte into the other fixed length byte pattern. The byte pattern is like a formula based "hash" or something similar into which a formula based algorithm...

lazy function definitions in scala

I've been learning scala and I gotta say that it's a really cool language. I especially like its pattern matching capabilities and function literals but I come from a javascript, ruby background and one of my favorite patterns in those languages is the lazy function and method definition pattern. An example in javascript is var foo = fu...