Showing posts with label design pattern. Show all posts
Showing posts with label design pattern. Show all posts

Monday, November 4, 2024

Enterprise Architectural Patterns

 An architectural pattern is a common standard for an architecture and solution to a problem. Unlike Design Patterns, an architectural pattern has a broader scope and can address big problems.  The architectural pattern address various issues of software engineering, such as computer hardware performance limitations, high availability and minimizing business risk. 

Software Patterns & Practices

The article describes how to deal with Design patterns and practices while developing your application. This article is basically a pointer to all the design patterns associated with the series. Please bookmark this to get links updated for all other articles that are added to the series. Click on a link below to read a pattern. 

Introduction

Software patterns are there and widely followed in the industry for a long time. In Software engineering, a pattern is a generalized solution to a common problem, a software design or an architecture for a given problem. This is the widely used solution to a problem specific to an industry, a person or a goal. A Software pattern can never be identified as a silver bullet to a problem but rather it is widely accepted a solution to a problem. There could be always a notion of adjustment to a pattern to adjust the specific need of the project that is worked on by the developers. 

Patterns are essentially formalisms and naming of nice idioms of coding. It is a way to give experience to programmers. It is a nice way to know that both the developers are talking about the same thing while discussing a problem. 

Software patterns are first introduced in 1995 by "gang of four": Design Patterns by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides. In this book, it is first discussed capabilities and pitfalls of Object oriented programming, and later on, it discusses the classic Design Patterns on OOPS. They introduced the first requirement of a software pattern while developing a piece of software in the industry. Better organizing a code is a lifelong learning experience for every developer and it is hard to follow when some functionality is needed to be implemented by a programmer. A software pattern just gives a sense of guidance to a developer while implementing a code or functionality for a problem. 

Monday, February 27, 2012

Inter-Process Communication using MemoryMappingFile

In an operating system, a Memory Mapping file are virtual storage place which has direct byte to byte correlation between the Virtual Address Space and the corresponding physical storage. So when we access the Virtual Address space via a memory mapping file we are directly communicating with the kernel space where the file is actually loaded. The portion of calculation between the physical storage and logical storage is hence avoided.

Memory Mapping files allows application to access files in the same way as memory. Generally as address between the physical storage and virtual memory address space, we cannot access the physical address directly. But using Memory Mapping Files, the process loads a specific range of address within the process address space with which the storage of memory into the file can be done by just assigning value to a dereferenced pointers. The IO operation on a MemoryMapping file is so fast that from the programmers point of view it seems to be like accessing the memory rather than actual physical storage. To increase performance memory mapping files are not actually stored to the disk file as well, but rather it will be stored automatically in background when FlushViewOfFile is executed or paging file is written. To Read more about memory mapping files, read here.

Memory Mapping file inside .NET Framework

.NET introduces a separate namespace to handle Memory Mapping files. Previously, we needed to do this using unmanaged Api's but with the introduction of managed API into the .NET framework library, it becomes very easy to handle MemoryMapping file directly from .NET library.

As memory mapping files are loaded into memory on a separate range of address space, two process can easily share the same page file instance and thus interprocess communication can be made with fast access to memory. It is recommended to back data with an actual disk file when large data is loaded into memory, so that there is no memory leak on the system when there is large memory pressure.

Saturday, February 4, 2012

Optimizing INPC Objects against memory leaks using WeakEvents

Working with WPF has always been a fun. Dealing with animation and richness in UI to its optimum level often gives you an edge to present something to your client and to ensure that your client shouts with a "WOW!". The Wow factor of applications can give you high rank in the first place, but increases expectation from the software. It is practically very hard to maintain with this expectation as time progresses. The survival of the fittest chooses one which best suits to the problem.

One of the major problems that developers face today is the memory leaks in an applications. Often the software that is built looks great but does not follow basic guidelines to ensure that the application is not memory hungry or even there are no existing memory leaks.

Note : By memory leak we mean, some portion of memory is not reclaimed by the garbage collector even though the object is not in use. 

By this way, the memory usage of the application increases at a certain extent and finally crashes with the OutOfMemoryException. To detect a memory leak there exists a large number of tools of which some are free while others are used as commercial purposes. Most of these problems can be fixed by either using Disposable pattern ( IDisposable interface) or manually de - referencing each and every object that are not in use. Sometimes, this can be also done in destructor / finalizers in .net too (but remember using destructors lose GC cycle).

Saturday, June 25, 2011

Some facts about Null in .NET

As I am tweeting around the facts on Nulls for last couple of days, I thought of writing a blog on that as many of you have already requested me on this regard. This post is basically dealing with Nulls and will go through only with basic C# stuffs, so for geeks, it is not recommended and you might end up knowing a little or almost nothing. So if you just here for time pass, then I refer to read on.

Considering the fact Nulls appear on any objects, we have mainly two categories of programmable storage in .NET.

  1. Nullables (generally mutable with exceptions like strings)
  2. Value Types / struct (generally immutable)
Nullables are types that either user defined or in framework in which one of its value can be null. .NET treats null specially. Say for instance :

Sunday, June 5, 2011

Working With Prism 4.0 (Hello World Sample with MVVM)

Modularity is one of the primary concern when working with a big projects. Most of us think of how we can implement our application that could be reusable across more than one applications. Patterns and Practices Team puts forward the notion of modularity with the help of Unity and Prism which most importantly focus on WPF and Silverlight applications. Being a WPF developer, it would be nice to take this apart and explain you a bit of how you can implement your application using Prism.

Before you begin, I must tell you, this is the most basic article that guides you step by step how you can write your first Prism based application and what are the advantages of building such kind of application. I will take this further in my next posts to make more concrete samples. So if you know the basics of how you can work with Prism, I would recommend you to read my next posts.

Also I assume you have some knowledge of Unity, WPF and MVVM to get you through with Prism.

Where do I find Prism? 

Prism is a framework introduced by Patterns and Practices Team which is available from here. After you install your bits, you will get a folder named Prism on your local drive. After you are done, lets start coding.

Thursday, April 28, 2011

Async support for Silverlight and WP7

Async support in C# language brings the new life to the modern application development to bring forth the same technique of writing your code and bring asynchrony easily. The main focus of async ctp is to ornament the language in such a way so that the developer could seamlessly create applications that brings asynchrony yet not dealing with its complexity. Hence using the new technique, asynchrony could easily achieved in a program without refactoring the whole program with lots of callbacks and method calls. I have already talked about it in a separate article. If you don’t know, please visit “Async CTP 5.0”.


Async CTP is released again recently and announced in MIX 11. Just after it is released, the first thing that everyone looks for is what is new in the release. As a matter of fact, I did jumped back to see them but eventually found out that there is nothing new in this build in terms of new features is concerned but the release focuses on fixes of performance adding debugging capabilities etc. I will definitely look back to them later in another post, but in this post I am going to talk about another important thing that featured with this release. As opposed to the previous release, the current release now supports Silverlight and Windows Phone 7 environments. This seems to be interesting.

What is Asynchrony?

The word asynchrony means something that is running without blocking other operations running in parallel. If you have created a background Thread to process some data, you are actually doing asynchronous job in background as your foreground operation does not get hampered. In vNext C# introduces Asynchrony using TPL. The two new keywords “async” and “await” could be used to make one sequential method asynchronous. Hence the new way of developing asynchronous program replaces the traditional approach where we needed to refactor the code totally to gain asynchrony in our application. Basically, this is done using the StateMachine to store the entire method into a form of states, and each states are delegated into batch of statements. The Task.ContinueWith is used in the system to ensure that the method body gets executed sequentially. Yes, it’s a compiler trick. If you want to know more about it, please read through my entire article on “Async CTP”.

Sunday, April 17, 2011

Closures in CSharp

Closures are an interesting feature for a language. I have heard a lot of questions around how we can declare closures in C# and hence I thought to start a blog on it. Over the internet, there are lots of examples on closures available which are taking help of functional languages like F#, yes it is very important in perspective of these languages as those are easy to declare and also inherently supported yet other languages like C# or VB.NET can also take help of these feature. Lets take a look how C# can take help of closures in this post.

What is a Closure? 

Closures may be defined as a set of behaviour or instructions that are encapsulated as an object such that it could be sent to other object yet can hold the context of the caller.  In other words, a closures are special object that are encapsulated into an object but can hold the context of the caller.

In C# we define closures using delegates. In C# 3.0 we have language support to easily declare a delegate in a program. This widely increases the use of delegates in the program using lamda expressions. Lets put the closures in terms of some examples.

Tuesday, March 22, 2011

Issue with RadioButtons and Binding for MVVM

Well, if you are working with WPF or silverlight, and in VS 2008, I think you would have definitely found this issue or will find it sooner.

Most of us when dealing with WPF applications must have been using MVVM pattern where you want to completely separate the presentation layer into a View Models. Well, it would be hard to create MVP or MVVM pattern yourself in other applications, but WPF has inbuilt support of MVVM with Command interfaces and Binding.  Binding is the concept which lets you to update the control whenever the underlying data object is modified and vice versa.

Most of the controls works great with Binding and hence can easily be used with MVVM pattern, but RadioButton has serious issue with it. In this post I will describe the problem with Radios and define some of the ways to solve it.

Tuesday, March 15, 2011

Internals of Events

If you are looking already at my internal series, you must by now know what does an entry from Internal series means. Yes, In each of those articles, I have tried to at least give some basic idea about the usage and later tried to show you some of the internal process that is happening to achieve the technique. In this post, as the name suggest, I will show how the event system works in .NET (or rather C#) and how this system is actually achieved into the system.

The Basics

Event is a special object in .NET which allows you to give notification to the external world. As far as I am concerned, its a means of communication between the object to the external world, or rather a means of inversion of control to the caller. Now what exactly an event does ?


Sunday, February 27, 2011

Dependency Injection & IOC

Well, after I introduced Inversion of Control with few simple examples in my previous post, I  thought it would be nice to take this discussion further with more implementation of Dependency Injection Principles. Later I would also take a look at some of the existing frameworks available with MS Patterns and Practices which follow these well known principles. If you remember my previous post on Inversion of control with interfaces, I have clearly stated that we could invert the control to some other module to make strong decoupling on one class with the other. In this post I will first cover the basics of the design principle on Dependency Injection and later talk about DI containers.

Dependency Injection

If you know about traditional Design Patterns, you should already know few of the most used pattern called Factory. Factory pattern allows you to put your object creation into a special module called Factory. Thus your objects will be created just inside your factory classes. But does it worth to put all the object creation inside your factory classes ? That means each of those classes will hold reference of all the objects that needed to be created. Lets see the code to show up what I am talking about :


public enum ProcessorType
{
    x86,
    x64
}
public class Computer
{
    public IntelProcessor GetProcessor(double speed, ProcessorType type, string version)
    {
        return new IntelProcessor { Speed = speed, Type = type, Version = version };
    }
}

public class IntelProcessor
{
    public string Version { get; set; }
    public ProcessorType Type { get; set; }

    public double Speed { get; set; }

    public string GetProcessorInfo()
    {
        return string.Format("{0} Ghz Processor for {1}, v{2}", this.Speed, this.Type, this.Version);
    }

    public override string ToString()
    {
        return this.GetProcessorInfo();
    }
}

Author's new book

Abhishek authored one of the best selling book of .NET. It covers ASP.NET, WPF, Windows 8, Threading, Memory Management, Internals, Visual Studio, HTML5, JQuery and many more...
Grab it now !!!