Articles

Design patterns in C# - Decorator

Image
Role The role of the Decorator pattern is to provide a way of attaching new state and behavior to an object dynamically. The object does not know it is being "decorated," which makes this a useful pattern for evolving systems. A key implementation point in the Decorator pattern is that decorators both inherit the original class and contain an instantiation of it. Illustration As its name suggests, the Decorator pattern takes an existing object and adds to it. As an example, consider a photo that is displayed on a screen. There are many ways to add to the photo, such as putting a border around it or specifying tags related to the content. Such additions can be displayed on top of the photo.   The beauty of this pattern is that: • The original object is unaware of any decorations. • There is no one big feature-laden class with all the options in it. • The decorations are independent of each other. • The decorations can be composed together in a mix-and-match

Overview of Test Driven Development

Test-Driven Development arose out of early literature around XP and other agile methods and was put forth, first and foremost, as a way to support refactoring . The idea was that writing your tests first forced you into thinking about tests, which in turn encouraged you to write more. The more tests you had, the easier it was to practice refactoring, or the art of making small incremental changes to your code to improve its structure. Proper refactoring involves making very small organizational changes to your code , then making sure that your tests still pass. Without proper test coverage, refactoring is much more difficult. The process of TDD is often described, in abbreviated form, as ‘‘Red, Green, Refactor,’’ meaning that first you write tests so that the tests fail (causing a ‘‘red light’’ in most testing GUIs), then you write code to make the tests pass (causing the ‘‘light’’ to turn green), and then you are free to refactor or improve the structure of your code, safe in the kn