What is Managed Code?

When you compile a .NET application you don’t generate code that can actually execute on your machine. You actually generate Microsoft Intermediate Language (MSIL or just IL). All .NET code is IL code. IL code is also called Managed Code, because the .NET Common Language Runtime manages it.

Leave a Comment

What is Common Language Runtime (CLR)?

It is a runtime environment of .NET Framework. The main function of Common Language Runtime (CLR) is to convert the Managed Code into native code and then execute the Program. It acts as a layer between Operating Systems and the applications written in .Net languages. CLR handles the execution of code and provides useful services for the implementation of the program. In addition to executing code, CLR provides services such as memory management, thread management, security management, code verification, compilation, and other system services.

The Common Language Runtime is the engine that compiles the source code in to an intermediate language. This intermediate language is called the Microsoft Intermediate Language.

During the execution of the program this MSIL is converted to the native code or the machine code. This conversion is possible through the Just-In-Time compiler. During compilation the end result is a Portable Executable file (PE).

This portable executable file contains the MSIL and additional information called the metadata (Metadata is data about data)

Metadata, stored in the compiled program, tells the CLR what language was used, its version, and what class libraries will be needed by the program. The Common Language Runtime allows an instance of a class written in one language to call a method of a class written in another language

Leave a Comment

What is .NET or .Net Framework ?

.NET Framework developed and maintain by Microsoft and that runs only on Windows Operating System like XP, Windows 2007 and Vista.

It enables developers to use lots of different Program languages to create software applications, websites, mobiles application, web services and many more

.NET provides tools and libraries that enable developers to create Windows software much faster and easier. .NET benefits end-users by providing applications of higher capability, quality and security. It also provides consistent object oriented environment to develop application in an standard way i.e. (use of classes and objects)

How .NET Architecture made up of?

  1. Common Language Runtime (CLR)
  2. Common Language Specification (CLS)
  3. Base Class Library (BCL)
  4. .NET Tools

Leave a Comment

What is are high level and low level languages?

High Level Language

High Level Language is a simple English language with set of Instruction and which is readable by human.

Code or Program written in such a way that is easily readable like a book.

For example: string strName = “My Name is Dot Net”;

There are certain rules to follow while writing a code but yes that is very easy to understand as compare to binary code

Now High Level Language is so simple that a programmer or a coder can develop standalone applications, web programs and other GUI interfaces very easily

High Level Language is divided into different forms like (C#, C, C++, VB, VB.Net, Python, Java, Perl, Ruby) etc. Among these languages you can use any one language at a time for a particular application.

High Level Language is designed to suit the requirements of a programmer

Compare to Low Level Language High Level Language is easier to understand, Learn and write.

 

Low Level Language

Low Level Language is a Machine Language or in simple words it’s a pure binary language i.e. 101111

For Human being is very difficult to understand these binary languages and these languages are only meant for specific computer architecture or hardware only representation is usually defined by the hardware manufacturer.

Low-level languages are closer to the hardware than are high-level programming languages

Low level language is a language that supports the machine side of the programming and does not provide human side of the programming.

Leave a Comment

What are Standalone and Web Programs ?

Standalone Programs

Standalone Programs are installed in a particular computer. Normally Standalone Programs doesn’t require internet connection to load external modules or libraries. Other programs like utility programs, application programs, entertainment programs, web browsers may comes under stand alone programs.

VB or VB.NET which is helps more to create these kinds of windows based applications

 

Web Based Programs

Web based programs which runs only on internet i.e. only with the support of www (World Wide Web)

Web based programs can also run on Intranet of local server system.

Standalone program like Mozilla IE helps us to open Web Programs like Facebook, Google, and Questpond

Creating web sites like questpond.com, face book, Google, YouTube all come under web based programs.

For web programming use:

(HTML, JavaScript, ASP.NET, CSS, ASP, Ajax, JQuery)

Leave a Comment

What is a Software Program?

If you have ever operated computers then you already have used a software program.  Some of the popular software program which is widely used Excel, word, power point, outlook, chat messengers, IE , Mozilla browsers web programs like Facebook,Google etc. In simple words software program is nothing but application with which you interact.

In Technicality way a program is nothing but a set of instructions that computer should understand then a program runs based on those set of instructions. A program is usually written by a software programmer in simple English language which is further gets converted to binary language i.e. (1010110).

A Computer Program can understand only binary code or language. Assembler which converts high level language i.e. Simple English Language (C, C++, C#, Java, VB) to Low Level Language (Binary Code).

The program that converted the assembly language into computer code was called the assembler.

 

 

Leave a Comment

Liskov’s Substitution Principle (LSP) with example in C#

Definition

Likov’s Substitution Principle states that if for each object m1 of type S there is an object m2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when m1 is substituted for m2 then S is a subtype of T.

Now let’s see the simple example of LSP Violation of code

In this example we have one common interface “ICustomer” which is inherits to two classes i.e.

ClsPaidCustomerSalesEnity, ClsFreeCustomerSalesEnity . two different classes which set and get properties and do calculation and print invoice as per customer status

For ClsPaidCustomerSalesEnity we have calculated special discount and printed the Invoice with customer name and amount

For  ClsFreeCustomerSalesEnity we have 0 discount and in PrintInvoice we return something

throw new NotImplementedException();

Means nothing was implemented in this method

//Interface Code

public interface ICustomer
{
  string CustomerName { set; get; }
  int CustomerCode { set; get; }
  int ProductQuantity { set; get; }
  double ProductRate { set; get; }
  double CalculateDiscountRate();
  string PrintInvoice(double _amount);

}

//Paid Customer Code
  public class ClsPaidCustomerSalesEnity : ICustomer
    {

        private string _customername;
        private int _customercode;
        private int _productquantity;
        private double _productrate;

        public string CustomerName
        {
            set { _customername = value; }
            get { return _customername; }
        }

        public int CustomerCode
        {
            set { _customercode = value; }
            get { return _customercode; }
        }

        public int ProductQuantity
        {
            set { _productquantity = value; }
            get { return _productquantity; }
        }

        public double ProductRate
        {
            set { _productrate = value; }
            get { return _productrate; }
        }

        public  double CalculateDiscountRate()
        {
            double rate = ProductQuantity * ProductRate;

            double discountamount = 0;
            double disrate = 20;

            discountamount = (disrate / 100) * rate;
            rate = rate – discountamount;

            return rate;
        }

        public string PrintInvoice(double _amount)
        {
            return “Product Invoice For Customer ” + CustomerName + ” with Total Amount ” + _amount;

        }

}

//Free Customer Code
public class ClsFreeCustomerSalesEnity : ICustomer
    {

        private string _customername;
        private int _customercode;
        private int _productquantity;
        private double _productrate;

        public string CustomerName
        {
            set { _customername = value; }
            get { return _customername; }
        }

        public int CustomerCode
        {
            set { _customercode = value; }
            get { return _customercode; }
        }

        public int ProductQuantity
        {
            set { _productquantity = value; }
            get { return _productquantity; }
        }

        public double ProductRate
        {
            set { _productrate = value; }
            get { return _productrate; }
        }

        public double CalculateDiscountRate()
        {
            return 0;
        }

        public string PrintInvoice(double _amount)
        {
            throw new NotImplementedException();
        }

    }

Both code is almost similar but only difference in implementation and inherits with common interface
Now let’s come to our window form application code

  ICustomer objIcust;
          List<ICustomer> listcust = new List<ICustomer>();

            objIcust = new ClsPaidCustomerSalesEnity();
            objIcust.CustomerName = “Paid Customer”;
            objIcust.CustomerCode = 001;
            objIcust.ProductQuantity = 5;
            objIcust.ProductRate = 20;
            listcust.Add(objIcust);

            objIcust = new ClsFreeCustomerSalesEnity();
            objIcust.CustomerName = “Free Customer”;
            objIcust.CustomerCode = 002;
            objIcust.ProductQuantity = 5;
            objIcust.ProductRate = 20;
            listcust.Add(objIcust);

            string printinvoice = “”;

            foreach (ICustomer iCust in listcust)
            {
                double amount = iCust.CalculateDiscountRate();
                printinvoice = iCust.PrintInvoice(amount);
                listBox1.Items.Add(“Invoice Report –> ” + printinvoice);              
            }

Problem with this code  when loop our Icustomer  collections it will work fine with

ClsPaidCustomerSalesEnity calculates Discount Rate and and print invoice properly

But when it loads ClsFreeCustomerSalesEnity  CalculateDiscountRate returns 0 and for PrintInvoice it throws new NotImplemented Exception which is totally wrong and on UI we don’t need any exception error  and writing Hacks and like if conditions is not proper way of design architecture

This is the problem with code

As it says it Free Customer code like paid customer code but unlike paid customer code there is not implementation of DiscountRate and Print Invoice method

So now let’s see the solution for above code using Likov’s Substitution Principle

A simple solutions but Customer Type i.e. paid customer class and free customer are not same difference in discount rate and print invoice implementation

If it looks like a duck, quacks like a duck, but needs batteries – wrong abstraction

So we need to create different interface for paid customer and for free customer

   public interface IFreeCustomer
    {
        string CustomerName { set; get; }
        int CustomerCode { set; get; }
        int ProductQuantity { set; get; }
        double ProductRate { set; get; }

    }

//use this for paid customer for printing invoice
    public interface IPaidPrintCustomer
    {
        string CustomerName { set; get; }
        int CustomerCode { set; get; }
        int ProductQuantity { set; get; }
        double ProductRate { set; get; }
        double CalculateDiscountRate();
        string PrintInvoice(double _amount);

    }

public class ClsPaidCustomerSalesEnity : IPaidPrintCustomer
{
//do the implementation as same as we did for customer
}

  public class ClsFreeCustomerSalesEnity : IFreeCustomer
  {
//do the implementation as same as we did for customer
  }

Then create separate objects and call it in UI

So Problem is solved successfully

Leave a Comment

Older Posts »
Follow

Get every new post delivered to your Inbox.