Specifying multiple interfaces for a parameter
public void Foo<T>(T myParam) where T : IObject, ITreeNode<IObject> { // whatever }
public void Foo<T>(T myParam) where T : IObject, ITreeNode<IObject> { // whatever }
Actually, doing arbitrary arity with type classes turns out to be incredibly easy: module Pred where class Predicate a where complement :: a -> a instance Predicate Bool where complement = not instance (Predicate b) => Predicate (a -> b) where complement f = \a -> complement (f a) — if you want to be … Read more
I have a single generic repository interface, which is implemented only once for a particular data storage. Here it is: public interface IRepository<T> where T : class { IQueryable<T> GetAll(); T Get(object id); void Save(T item); void Delete(T item); } I have implementations of it for EntityFramework, NHibernate, RavenDB storages. Also I have an in-memory … Read more
I believe that the more you start to develop using design patterns, you’ll find more and more often where composition is going to be favored over inheritance. I actually believe in the Head First: Design Patterns book that “Favor Composition Over Inheritance” is one of the primary design principles. Your example of being able to … Read more
Thoughts: Avoid extending JFrame as it ties your GUI to being, well a JFrame. If instead you concentrate on creating JPanels instead, then you have the freedom to use these JPanels anywhere needed — in a JFrame, or JDialog, or JApplet, or inside of another JPanel, or swapped with other JPanels via a CardLayout. Avoid … Read more
The difference can be seen in the two constructors: Dependency: The Address object comes from outside, it’s allocated somewhere else. This means that the Address and Employee objects exists separately, and only depend on each other. Composition: Here you see that a new Engine is created inside Car. The Engine object is part of the … Read more
public static class Extensions { public static Func<T, TReturn2> Compose<T, TReturn1, TReturn2>(this Func<TReturn1, TReturn2> func1, Func<T, TReturn1> func2) { return x => func1(func2(x)); } } Usage: Func<int, int> makeDouble = x => x * 2; Func<int, int> makeTriple = x => x * 3; Func<int, string> toString = x => x.ToString(); Func<int, string> makeTimesSixString = … Read more
Mark, This is an interesting question. You will find as many opinions on this. I don’t believe there is a ‘right’ answer. This is a great example of where a rigid heirarchial object design can really cause problems after a system is built. For example, lets say you went with the “Customer” and “Staff” classes. … Read more
Composition This is a design concept (not really a pattern). This term is used when you want to describe one object containing another one. It occurs very often in Composition over inheritance discussion. Moreover, composition implies strong ownership. One objects owns (i.e. manages the lifecycle) of another object. When parent is destroyed, all children are … Read more
You are not making a mistake. The key idea to understand here is currying – that a Haskell function of two arguments can be seen in two ways. The first is as simply a function of two arguments. If you have, for example, (+), this is usually seen as taking two arguments and adding them. … Read more