.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

when abstract class and when interface

Posted By:      Posted Date: September 18, 2010    Points: 0   Category :ASP.Net
hi...need a practical scenario where interface can be used and where abstract class and also the need for constructors and destructors practically?? theoritically i know the differences ..but during coming to the implementation how to decide??...like why do u declare a class as abstract... thanks in advance 

View Complete Post

More Related Resource Links

what is the difference between abstract class and interface

hi,recently i went for an interview they ask me what is abstract class ,interface and its difference
I said abstract class contain abstact method ,abstract method is a method with no body.Abstract class cannot be instantiated.Abstract class is a base class it required derived class for the implementation of method.
Interface is a syntactical contract that all derived class should follow 
it define properties ,method,events which are known as member of interface.
Then They asked me what is the difference between them. I said 
abstract class interface 
1.abstact class can implement method 1.interface cant
2.abstact class can contain constructor, 2.interface cant
3.abstract class cannot support multiple 3.interface support
Then they said some different answer I said dont no.
Then they ask me when i should make abstract class for an project and when 
i should make interface.
I said if suppose there is two class which must be having method with different logic then we sholud make abstract class. 
and if suppose we have two class having method .with different logic then we can make interface .
Am i correct with my explainatio

abstract away the source of the connection string using a class with a static property.

ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.

The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. The items inside appSettings are items that need to be configurable depending upon the environment, for instance, any database connection strings will change as you move your application from a testing and staging server into production.

Let's abstract away the source of the connection string using a class with a static property.

Singleton Pattern and Abstract Class


I know what Singleton Pattern means and Abstract class means.

What I wanted to know was how would this apply to real world.

Could anyone give me any good example or simple explanation.

Say I have a simple website, why would I use any of the above if any.

Why would it simplify my architechture.

Thanks in advace. 

Abstract class properties work when not implemented?

Hi, I was just looking at a code example and was confused by the behavior of classes implementing an abstract class. So the project has an abstract class named GeneralItem with some abstract properties. Another class named NspItem inherits GeneralItem. NspItem does not implement any of the abstract properties from GeneralItem yet I can write code that successfully sets those properties. How is that working? Is the compiler automatically creating them for me? Example: public abstract class GeneralItem { public string Description { get; set; } } public class NspItem : GeneralItem { public NspItem() { } } static class Program { [STAThread] static void Main() { NspItem item = new NspItem(); item.Description = "Some String"; Console.WriteLine(item.Description); } } //Output would be: Some String

LINQ to SQL compiler error CS1519: Invalid token 'void' in class, struct, or interface member decl

I get the following compiler errors when creating my first LINQ to SQL class (I just dragged a table "ProfileExtended" onto the designer and hit build):DataClasses.designer.cs(31,11): error CS1519: Invalid token 'void' in class, struct, or interface member declaration these are the offending lines of autogenerated code:#region Extensibility Method Definitions  partial void OnCreated();  partial void InsertProfileExtended(ProfileExtended instance);  partial void UpdateProfileExtended(ProfileExtended instance);  partial void DeleteProfileExtended(ProfileExtended instance);  #endregion

Can WCF inherit a standard class interface?????


I have a standard Object Interface (read: no data contract decorations)  that is inherited by a number of classes. I want to enable this inteface for a new WCF service.

For example:

public interface iVendor


Use UserControl, where the base class is an abstract one.




When I inherits my usercontrol from an abstract class, I got the warning message on design time.

How can I overcome this warning message?

The designer must create an instance of type but it cannot because the type XYZ is declared as abstract.


Thanks :)

Interface, Abstract or Inheritance?



I have a table which houses two entities. StaticProgram and DynamicProgram. There is one column in that table called ProgramType which determines if a program is of Type static or Dynamic. Though these two entities are stored in one table (I am guessing because the primitive fields for Static and Dynamic programs are exactly the same) but from a business point of view these are two VERY different entities.

So, I created two Classes StaticProgram and DynamicProgram. However, I donot want to create two seperate Data Access Classes because it is going to be the exact same code replicated twice. I tried creating a "Program" class as base class and inherited StaticProgram and DynamicProgram classes but down casting is not supported so I can't return a "Program" object from the data access class and cast it to "StaticProgram" class.

So, what are my options? Can I create an IProgram interface and have StaticProgram and DynamicProgram implement that interface and have my Data Access class return IProgram? Any other suggestions?

I would appreciate your help!!

Interface object Versus Class Object


Asslam o Alaikum

namespace Interface
    interface IMyInterface
        void Start();    
        void Stop();

    class Program : IMyInterface
        void IMyInterface.Start()
            Console.WriteLine("\n Void Start Method Implement");
        void IMyInterface.Stop()
            Console.WriteLine("\n Void Stop Method Implement");
        static void Main(string[] args)
            IMyInterface iMyInterface = new Program();

1. IMyInterface iMyInterface = new IMyInterface(); // if i create the object of interface i get Error
2. Program iMyInterface = new Program(); // if i create the object of program i can't get the property of Interfaces i.e. Start(); stop();
3. IMyInterface iMyInterface = new Program(); // This will work fine

i want know the difference about 3 points can any body claer it ..


Regarding Creating Custom Field type Class Inheriting from IFieldEditor Interface and UserControl C


How to enable the hidden labels On Create Column Page after selecting our Custom Field type before just ckicking OK so that all those labels appear.

When to use Interface instead of class, in VS 2008



Why do we use Interface instead of class in VS 2008?

What between about Interface and class in VS 2008,high performance?

Abstract Class


what is the function of abstract class, why design pattern need to build BLL and DAL

anyone give an example for my reference as I am getting strat to build my web-based  project 

Abstract class


In my engineering i never understand abstract class

but now after enter in developing field i go through various kind of RND work

Please solve my problem about abstract  class 

My code below

in my connection class i declare one more class name is shape


public abstract class Shape
    public abstract void Test(int x, int y)
public abstract class Shape1 : Shape
public class Shape2 : Shape1

How to set view properties from another class/interface


There is a SearchPage which has a properties ErrorMessage, SuccessMessage etc. This is basically a MVP pattern so for each page(view) there is IView that contains definitions for all the properties

I am using decoratoe pattern to set these peoperties dependingon the message type. There is another Interface IBaseMessage which has a method DisplayMessage() and a class BaseMessage which implements the interface. This class has a definition of the view

Interface IbaseMessage






public Iview _view{get; set;}



_view.Warning ="<message>"



Here, I am not able to set the message to the view properties. I am getting the error as "Object reference not set to an instance of the object"

Somehow the access is not going till theview from the class BaseMessage. I may be missing something. Please help

Appreciate your help!


force use of interface instead of directly instentiating implemented class

    interface ITest
        int Add();
    class Test:ITest
        public int Add()
            throw new NotImplementedException();

    public class Program

        static void Main(string[] args)
            // OK
            ITest t = new Test();
            // disallow below 
            Test t1 = new Test();
           // Since both works, how to stop others from directly instentiating implemented class


Adding IServiceClient interface to generated proxy service client class

would it be possible to add a service client interface to a generated service client class in a generated service proxy in order to achieve easier testability?
Here's an example of what I am asking the way I do it manually http://blog.vuscode.com/malovicn/archive/2009/11/01/design-for-testability-wcf-proxies.aspx

This would not break backward compatibility (safe to be added)

Is this question more for Connect? :)


Abstract Factory Design in C# , Vb.NET

Provide an interface for creating families of related or dependent objects without specifying their concrete classes
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend