Understanding Adapter Pattern

Generally the adapter pattern transforms one interface into another, but it can simply wrap the behavior to isolate your class from the underlying implementation. In your case, you are using an adapter, but you could just as easily have defined the DAO objects to simply implement the interface and programmed against the interface. The adapter … Read more

What is the difference between Strategy pattern and Dependency Injection?

DI and Strategy work in the same way, but Strategy is used for more fine-grained and short-lived dependencies. When an object is configured with a “fixed” Strategy, for example when the object is constructed, the distinction between Strategy and DI blurs. But in a DI scenario it is more unusual that the dependencies of objects … Read more

C# – Object Composition – Removing Boilerplate Code

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

How does TransactionScope work?

Hope this helps: http://msdn.microsoft.com/en-us/magazine/cc300805.aspx For those unfamiliar with TransactionScope, it is part of the System.Transactions namespace new to the Microsoft® .NET Framework 2.0. System.Transactions provides a transactions framework fully integrated into the .NET Framework, including but not limited to ADO.NET. The Transaction and TransactionScope classes are two of the most important classes in this namespace. … Read more

Is This Use of the “instanceof” Operator Considered Bad Design?

The Visitor pattern is typically used in such cases. Although the code is a bit more complicated, but after adding a new RecordType subclass you have to implement the logic everywhere, as it won’t compile otherwise. With instanceof all over the place it is very easy to miss one or two places. Example: public abstract … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)