Saturday, April 30, 2011

[C# - PRISM 4.0] Building highly flexible and modular applications

I already showed you some time ago how to create good and efficient code by using the S.O.L.I.D. design principles. This time I would like to focus on PRISM 4.0 and its features.

The goal for good software architecture is always the same : produce code that is flexible, highly modular, easy to maintain, simple to extend and overall as independent as possible.

This can very well be achieved by applying best practices and having good programming skills but it will get even more powerful when using existing frameworks that already contain all foundations and have all necessary patterns in place. One of the most mature and advanced frameworks is PRISM 4.0 (patterns & practices) which will allow you to be much more productive when correctly used.

image

Prism 4.0 provides guidance to help easily design and build rich, flexible, and easy-to-maintain applications. It works with Microsoft .NET Framework 4.0 and Silverlight 4, the latest technologies currently available.

It especially works well with the following project types:

  • Silverlight Applications
  • WPF Applications
  • Windows Phone 7 Applications

Furthermore it support MVVM and MEF and is open for usage with different dependency injection containers (by default it uses Unity). It is build from ground up using Design Patterns that favor separation of concerns and loose coupling which allow Composite Applications.

The goal is to partition applications into a number of discrete, loosely coupled, semi-independent components and modules that can be individually developed, tested, and deployed by different subteams.

image

PRISM 4.0 helps to achieve a very clean separation between UI and Business Logic. Efficient reuse of existing functionalities and a clean separation of concerns between horizontal capabilities (logs, custom authentication, etc…) can be very quickly attained. When using MEF it is also extremely easy to create modular applications where functionalities can be dynamically added (even during runtime).

The existing classes and functionalities really help very much and provide a robust basis on which you can build on. The concentration can really be on the business functionalities and not the surrounding shell.

image

image

Needless to say that you will have to familiarize yourself with the framework and look into examples on how to use it correctly. You should also decide if you really need to be so modular and if you will have an added value because for monolithic and simple applications it might not be advisable to have such an approach. And surely you could also build everything yourself but you might take a look and evaluate if it is usable in your context. Did I mention that it is free ? So don’t hesitate and look for yourself and try it out, it might help you to build better applications quicker, with less stress and for less money !


Share/Save/Bookmark

Thursday, April 28, 2011

[C# and Language] DevLabs Website

Microsoft is working constantly on new incubation projects to extend existing language features and add new ones. Some of the early versions of those new features can be tested on the DevLabs website. When they are considered to be accepted and they have finished their incubation period they are moved to the respective product sections (as it was done for the Reactive Extensions) or are directly integrated into the corresponding products such as Visual C#.

image

Currently there are the following incubation projects available:

  • TC Labs: Solver Foundation (build and solve real optimization models)
  • TC Labs: TPL DataFlow (extensions to the .NET 4.0 TPL addressing additional scenarios)
  • TC Labs: Dryad (process large volumes of data in many types of applications and enable LINQ on HPC systems)
  • TC Labs: Sho (connect IronPython scripts with compiled .NET code for fast and flexible prototyping)
  • Doloto (AJAX Download Time Optimizer)
  • Code Contracts (extensions to the existing .NET 4.0 version)
  • Axum (parallel applications development based on the actor model)
I am personally currently looking into TPL DataFlow, CodeContracts and Axum (since some time already) and will take some time to give you feedback on my experience in the next weeks.


Share/Save/Bookmark

Thursday, April 14, 2011

[Tutorial] Common Design Patterns in C# 4.0
Part1: Introduction Gang of Four Design Patterns

Design Patterns provide standardized and efficient solutions to software design and programming problems that are re-usable in your code. Software Architects and developers use them to build high quality robust applications.

However, you have to take care to select the right pattern for the right problem. If you need to modify the initial pattern too much, this may indicate that it is not adapted to your needs and may in the worst case lead to unmaintainable, complex and inefficient code. The opposite of what you intend when using Design Patterns !!

You may also create your own custom Design Patterns. Whenever you come up with a certain solution that is reusable in a vast majority of your projects, you may decide to abstract a design pattern out of it. Then you may create your own library of patterns and share them within your whole company, thus creating standards and ameliorating maintainability.

In this series of blog posts I am going to show you how to use the well known Gang of Four (GoF) Design Patterns in C# 4.0 code. Those patterns will work well in any project that uses C# but especially in WPF, WCF, WinForms, ASP.NET projects.

The GoF Design Patterns are divided into 3 categories : Creational Patterns, Structural Patterns and Behavioral Patterns. In my following blog posts I am going to explain each GoF Design Pattern in detail and will show you examples of how to write good C# 4.0 code that implement those patterns.

Creational Patterns

  • Abstract Factory: Create instances of classes belonging to different families

  • Builder: Separate representation and  object construction

  • Factory Method: Create instances of derived classes

  • Prototype: Clone or copy initialized instances

  • Singleton: Class with only one single possible instance

Structural Patterns

  • Adapter: Match interfaces of classes with different interfaces

  • Bridge: Separate implementation and object interfaces

  • Composite: Simple and composite objects tree

  • Decorator: Dynamically add responsibilities to objects 

  • Facade: Class that represents subclasses and subsystems

  • Flyweight: Minimize memory usage by sharing as much data as possible with similar objects

  • Proxy: Object that represents another object

Behavioral Patterns

  • Chain of Responsibility: Pass requests between command and processing objects within a chain of objects

  • Command: Encapsulate a method call as an object containing all necessary information

  • Interpreter: Include language elements and evaluate sentences in a given language

  • Iterator: Give sequential access to elements in a collection

  • Mediator: Encapsulates and simplifies communication between objects

  • Memento: Undo modifications and restore an object to its initial state

  • Observer: Notify dependent objects of state changes

  • State:Change object behavior depending on its state

  • Strategy: Encapsulate algorithms within a class and make them interchangeable

  • Template Method: Define an algorithm skeleton and delegate algorithm steps to subclasses so that they may be overridden

  • Visitor:  Add new operations to classes without modifying them

There are also many other types of pattern such as: Parallel Patterns, SOA Patterns, Enterprise Architecture Patterns, etc… So if you work in the respective area don’t hesitate to look up patterns that may help you to be more efficient and build better applications.


Share/Save/Bookmark

Thursday, April 7, 2011

[MVP Nomination] Happy to be awarded as MVP Visual C# !!!

Beginning of the month I got an email from Microsoft containing that I am awarded Microsoft MVP Visual C#. After working in the industry since soon more than 14 years I am very happy and honored for being selected and proud to call myself MVP !!!

MVP

I want to take some time and thank Loic Baumann (MVP Visual Studio ALM) and Michel Perfetti (MVP Visual Studio ALM) for their support as well as my MVP Lead for having me nominated.

Also a big thank you to Microsoft for putting their trust in me. I will do my best and continue sharing my knowledge with the community. So be prepared for many new blog posts and articles in the technical press on Software Architecture & Design, Visual C# and Windows Azure, which are my main interests. I will also concentrate on speaking much more at conferences so I would be glad to see you at any Microsoft events (TechDays, MS Days, etc…).

Who knows, I may even write a book on Software Architecture if I find the time. I really would love to do that. So stay tuned and continue following me if you like this Blog !


Share/Save/Bookmark