The blog has moved to the new site F10Debug.com

Monday, April 4, 2016

How oops concepts is implemented in the Asp.Net

How oops concepts is implemented in the Asp.Net 

Posted by User: Sneha Sharma

Question: 
I need a brief details about the opps concepts implemented in the Asp.Net .Though multiple inheritance is not supported in C# How can we inherit from one master page to many aspx pages.

Ans:
Multiple inheritance means one class is derived from multiple classes, which is not possible in case of c#. Which can be achieved using interface.

In case of Master page and child page, we are not deriving one child page from many master pages, we are deriving many independent child classes from one parent class.

Ex:  Here how master page and child page uses oops concepts...Many individual child classes (child class) are derived from only one master page. (Parent class)



ChildPage1: Masterpage1

ChildPage2: Masterpage1............ChildPageN: MasterPage1


Real Time Example: 

Here we have derived two child classes (About, Default child pages) from one parent class (Page class - master page)

Partial class About
       Inherits Page
End Class

Partial class Default
       Inherits Page
End Class

here we are not deriving one child page (child class) from many master pages (Parent classes)

For Ex: 

Childpage1:   MasterPage1, MasterPage2

Hope this will clear your doubts. Let me know if any questions...


3 comments:

  1. Replies
    1. Thank you @Sneha sharma.

      If you like our answers, you can subscribe to my blog, by submitting your email id.

      Regards,
      Jatin Nahar

      Delete
  2. Hi Jatin is correct,
    However some times Partial classes can also be good choice.

    C# program that uses partial class

    class Program
    {
    static void Main()
    {
    A.A1();
    A.A2();
    }
    }

    Contents of file A1.cs: C#

    using System;

    partial class A
    {
    public static void A1()
    {
    Console.WriteLine("A1");
    }
    }

    Contents of file A2.cs: C#

    using System;

    partial class A
    {
    public static void A2()
    {
    Console.WriteLine("A2");
    }
    }

    Output

    A1
    A2

    ReplyDelete