Some days back one of my readers asking me a question about why one should migration from .net 1.1 to the latest framework. Here is the part of discussion:
Reader: Why the product should be migrated from .net Framework 1.1 to later framework if product is working as expected without any issue. What are different advantages (performance and system stability) regarding the upgrade to higher versions of the framework? What can be a good reason for the client to allow us to work on migration?
Me: Migrating existing .Net application developed using older version of .Net framework to the latest version is always worth considering, for many reasons. .Net application should be upgraded from time to time to the latest version of .Net to accrue the maximum benefits from technology advancement. Some of the reason/benefits are as follow: Read more »
An Abstract class without any implementation just looks like an Interface; however there are lot of differences than similarities between an Abstract class and an Interface. Let’s explain both concepts and compare their similarities and differences.
What is an Abstract Class?
An abstract class is a special kind of class that cannot be instantiated. So the question is why we need a class that cannot be instantiated? An abstract class is only to be sub-classed (inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards.
What is an Interface?
An interface is not a class. It is an entity that is defined by the word Interface. An interface has no implementation; it only has the signature or in other words, just the definition of the methods without the body. As one of the similarities to Abstract class, it is a contract that is used to define hierarchies for all subclasses or it defines specific set of methods and their arguments. The main difference between them is that a class can implement more than one interface but can only inherit from one abstract class. Since C# doesn’t support multiple inheritance, interfaces are used to implement multiple inheritance.
Both Together
When we create an interface, we are basically creating a set of methods without any implementation that must be overridden by the implemented classes. The advantage is that it provides a way for a class to be a part of two classes: one from inheritance hierarchy and one from the interface.
When we create an abstract class, we are creating a base class that might have one or more completed methods but at least one or more methods are left uncompleted and declared abstract. If all the methods of an abstract class are uncompleted then it is same as an interface. The purpose of an abstract class is to provide a base class definition for how a set of derived classes will work and then allow the programmers to fill the implementation in the derived classes.
There are some similarities and differences between an interface and an abstract class that I have arranged in a table for easier comparison:
| Feature |
Interface |
Abstract class |
| Multiple inheritance |
A class may inherit several interfaces. |
A class may inherit only one abstract class. |
| Default implementation |
An interface cannot provide any code, just the signature. |
An abstract class can provide complete, default code and/or just the details that have to be overridden. |
| Access Modfiers |
An interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as public |
An abstract class can contain access modifiers for the subs, functions, properties |
| Core VS Peripheral |
Interfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovable interface. |
An abstract class defines the core identity of a class and there it is used for objects of the same type. |
| Homogeneity |
If various implementations only share method signatures then it is better to use Interfaces. |
If various implementations are of the same kind and use common behaviour or status then abstract class is better to use. |
| Speed |
Requires more time to find the actual method in the corresponding classes. |
Fast |
| Adding functionality (Versioning) |
If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method. |
If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly. |
| Fields and Constants |
No fields can be defined in interfaces |
An abstract class can have fields and constrants defined |
| Is-a vs able or can-do |
Interfaces are often used to describe the peripheral abilities of a class, not its central identity, e.g. an Automobile class might implement the Recyclable interface, which could apply to many otherwise totally unrelated objects. |
An abstract class defines the core identity of its descendants. If you defined a Dog abstract class then Damamation descendants are Dogs, they are not merely dogable. Implemented interfaces enumerate the general things a class can do, not the things a class is. |
| Homogeneity |
If all the various implementations share is the method signatures, then an interface works best. |
If the various implementations are all of a kind and share a common status and behavior, usually an abstract class works best. |
| Maintenance |
If your client code talks only in terms of an interface, you can easily change the concrete implementation behind it, using a factory method. |
Just like an interface, if your client code talks only in terms of an abstract class, you can easily change the concrete implementation behind it, using a factory method. |
| Adding functionality |
If you add a new method to an interface, you must track down all implementations of that interface in the universe and provide them with a concrete implementation of that method. |
If you add a new method to an abstract class, you have the option of providing a default implementation of it. Then all existing code will continue to work without change. |
Introduction
This article is about understanding the working concept of destructor in C#. I know you all may be thinking why a dedicated article on simple destructor phenomenon. As you read this article you will understand how different is C# destructor are when compared to C++ destructors.
In simple terms a destructor is a member that implements the actions required to destruct an instance of a class. The destructors enable the runtime system, to recover the heap space, to terminate file I/O that is associated with the removed class instance, or to perform both operations. For better understanding purpose I will compare C++ destructors with C# destructors. Read more »
They both are same but each one has some draw back and advantages.
lock is more concise over monitor; it releases the lock from the blocked code even if there is exception generated within blocked code. There could be deadlock with lock if we do not use it correctly, also when we use lock the thread will wait for infinite time to get the lock on object. Read more »
In the early days of computing, a program would begin execution and then proceed through its steps until it completed. If the user was involved, the interaction was strictly controlled and limited to filling in fields.
Today’s Graphical User Interface (GUI) programming model requires a different approach, known as event-driven programming. A modern program presents the user interface and waits for the user to take an action. The user might take many different actions, such as choosing among menu selections, pushing buttons, updating text fields, clicking icons, and so forth. Each action causes an event to be raised. Other events can be raised without direct user action, such as events that correspond to timer ticks of the internal clock, email being received, file-copy operations completing, etc. In programming, you are often faced with situations where you need to execute a particular action, but you don’t know in advance which method, or even which object, you’ll want to call upon to execute it. For example, a button might know that it must notify some object when it is pushed, but it might not know which object or objects need to be notified.
C# adds on value to the often mentioned world of event driven programming by adding support through events and delegates. Read more »
Introduction
DotNet developers can free themselves from tedious memory management for their application as Microsoft Framework and CLR do it automatically.CLR provides a mechanism called as Garbage Collection which manages your applications memory. In this session we will discuss how garbage collector works and how it affects the performance of your Applications.
When you create an object using new () operator, the object’s memory is obtained from the managed heap. When the garbage collector decides that sufficient garbage has accumulated, it performs a collection to free some memory. This process is fully automatic, but there are a number of factors that you need to be aware of that can make the process more or less efficient. Read more »
Best Practices, CSharp (C#), System Analysis and Design
|
.Net, Dispose, Finalization, Garbage Collection, Garbage Collection Algorithm, Generations, Implement Dispose method, Performance, System.GC
In this article we will understand some of the concepts of object-oriented programming in C# like objects and classes. To read this article you must have C# programming basics.
Read more »
Introduction
The .NET CLR provides a common context within which all .NET applications execute, regardless of teh language in which they are written.CLR is responsible for handling every aspects of the managed code such as memory and resource management, secure environment to run in, garbage collection , access to the operating systems services etc. Code that targets the CLR is commonly known as managed code Read more »
CSharp (C#)
|
.Net, CLR, Code Execution, Compiling MSIL, Execution, Garbage Collection, interoperability, JIT, Just-in-Tim, Managed Code, Managed Execution Process, MSIL, resource management
Do you want to prepare for the Interview, Here is a list of interview questions and answer related to OOPs asked by MNCs will help you to prepare for the interview quick and test your skill – ultimately to make you confidant.
Default Access modifiers in C#?
An enum has default modifier as public
A class has default modifiers as Internal . It can declare members (methods etc) with following access modifiers:
public
internal
private
protected internal
An interface has default modifier as public
A struct has default modifier as Internal and it can declare its members (methods etc) with following access modifiers:
public
internal
private
A methods, fields, and properties has default access modifier as “Private” if no modifier is specified. Read more »
Do you want to prepare for the Interview, Here is a list of interview questions and answer related to .Net asked by MNCs will help you to prepare for the interview quick and test your skill – ultimately to make you confidant.
What is the .NET Framework?
Answer 1: The Microsoft .NET Framework is a platform for building, deploying, and running Web Services and applications. It provides a highly productive, standards-based, multi-language environment for integrating existing investments with next-generation applications and services as well as the agility to solve the challenges of deployment and operation of Internet-scale applications. The .NET Framework consists of three main parts: the common language runtime, a hierarchical set of unified class libraries, and a componentized version of Active Server Pages called ASP.NET. Read more »
Introduction:
When you install the Visual Studio .NET, the common language runtime has the Global Assembly Cache (GAC). The GAC stores assemblies that are shared by the several applications on the computer called as Shared Assembly or Global assembly. This shared assembly is globally available to all the applications on the computer.
Changing private assembly into a shared assembly:
A private assembly is normally used by a single application and is stored in a application directory or sub-directory beneath. This assembly cannot be shared by other applications. To make it globally available this assembly we need to install assembly in the global assembly cache (GAC). But to be installed in a GAC, it must have a Strong Name. Read more »
CSharp (C#)
|
.Net, .snk, Assembly, AssemblyKeyFile, C#, common language runtime, GAC, gacutil, Global Assembly Cache, private assembly, shared assembly, Strong Name
The easiest way to copy a file in a .NET program is to call the File.Copy method, supplying it the source and destination files. It could hardly be simpler than this:
File.Copy(srcFilename, destFilename);
That method will throw IOException if there is an existing file of the same name as destFilename. If you want to overwrite existing files, call the overload and specify true for the overwrite parameter:
File.Copy(srcFilename, destFilename, true);
File.Copy certainly is very easy to use, but as I mentioned in the previous section, it suffers from the large file copy problem. That is, using File.Copy to copy a very large file from one machine to another can cause the source machine to run out of memory. For example, I encountered that problem when executing a statement of this form:
File.Copy(@"\\server\data\file.dat", @"d:\data\file.dat", true);
If you want to copy a file and not encounter those problems, you have to write your own copy method. Read more »
Windows Server 2008 provides at least three different command line utilities for copying files. The familiar COPY and XCOPY commands have been around since the early DOS days. And ROBOCOPY, a more robust and feature-rich tool, began shipping with Windows Vista and Windows Server 2008. These tools work just fine in most cases. But all three suffer from a fatal flaw when you’re trying to copy a file that’s larger than available memory.
Manifestation of the Problem
Our main servers are quad-core machines with 32 gigabytes of RAM, running the 64 bit version of Windows Server 2008. Our custom format repository file is about 90 gigabytes in size. That’s after compression. In addition to daily backups, I periodically need to copy that file to another computer. And that’s where the problems start. Read more »
Pre-compilation For Deployment
Pre-compilation for deployment creates an ‘executable’ (no source code) version of your web application. With pre-compilation for deployment you give the aspnet_compiler the path to your source code, and the path to a target directory for the compilation results, like below.
aspnet_compiler -p "C:\MyDevelopment\WebSite1" -v / C:\Staging
Read more »
Introduction
Garbage collection is a process of releasing the memory used by the objects, which are no longer referenced. This is done in different ways and different manners in various platforms and languages. We will see how garbage collection is being done in .NET.
Read more »