What is Caching in ASP.NET explain?

caching in ASP.NET

caching is a technique helps a developer to build a most robust, scalable and high-performance website.

Caching is technique helps the developer to store the final rendered HTML page or parts of the web page or sometimes to store even data in web server.

Saving the parts of page and data will help to save the server resource and improve the performance of an application.

The different types of caching techniques available in asp.net are mention below.

1. Output caching
2. Page caching
3. Data caching etc.

When To Use Abstract Class in C# | What Is the Purpose of an Abstract Class

The perfect way to understand where and When To Use Abstract Class in C# is? When there is “IS-A” relation between classes, so next question comes what is “IS-A” relation?.

Example of “IS-A” relation between classes

  • A car is a Vehicle.
  • A bike is a Vehicle.

So now Vehicle can be an abstract class with common implementation of

  • The number of tires.
  • Seating capacity.
  • etc.

As per above example, you can correlate to any scenario, and you would come to know when to use an abstract class.

To understand better one more example would be like Scroll Mouse is a Mouse and Optical Mouse is a Mouse so Mouse would be an abstract class.

 

I hope you understand, how to identify an abstract class and When To Use Abstract Class in C#. Last but not the least topic to be covered would be

What Is the Purpose of an Abstract Class?

As per above example, you quickly understand that abstract classes are always base classes. The primary purpose of an abstract class is to create a class which can extend the base class properties.

In other words, the purpose of an Abstract class is to have a standard functionality in the base class that can be inherited to multiple subclasses, without implementing the entire class features.

Abstract Class in C# | Abstract Class in C# With Real Time Example

Abstract Class in C# is one of the essential core concepts of .NET framework. As a lot of developers learn, just by adding an abstract keyword to class is termed as an abstract class. Technically definition might be correct, but it’s not the definition need to be understood.

As being a C# .NET developer, one must understand what an abstract class is, why is an abstract class is used for and when to use the abstract class using a real-time example.

What is an Abstract Class in C#

As per OOPS concept, abstract means concentrate on functionality rather than how it is implemented. The same rule applies to the abstract classes and abstract methods in C#.NET.

Abstract classes are meant to be the role models in business layer creation in other words abstract classes are used to create the base classes. Abstract classes may have an implementation or may not have an implementation for methods. This special feature makes the abstract classes more powerful.

Why we are not able to create an instance of the Abstract class?

As abstract classes may have abstract methods means without implementation or body. So creating an instance of an abstract class without implementation is like searching for nothing inside a dark room. That’s the reason, why we are not able to create an instance of an abstract class.

How to create an instance of an Abstract class?

No, we cannot create an instance of the abstract class. Abstract keyword enables you to create classes, or its methods which are incomplete must be implemented in the derived classes.

Means to create an instance of the derived class, which can give access to abstract class properties and methods.

Abstract class creation in C# – Abstract class examples in C#

The basic example of abstract class creation.

Abstract method creation

The basic example of an abstract method creation inside an abstract class.

Non-Abstract method creation inside an abstract class

The basic example of a Non-abstract method creation inside an abstract class.

Abstract properties creation

The basic example of an Abstract properties creation inside an abstract class.

Abstract class Implementation

Finally, The basic example of an Abstract class creation and implementation.

 

Hi,

Friends feel free to ask any queries on abstract classes in c#.

Thank you.

Why can’t we create an object for Abstract Class in C#?

There are a lot of articles on the internet to explain “why can’t we create an object for Abstract Class in C#?”. None of them give you a straight answer or definition’s which you cannot understand and leads to confusion.

And few say it is the basic rule of the Abstract class, Now let’s see the perfect answer why?

Why Can’t We Create an Object for Abstract Class in C#?

Abstract classes may have abstract methods so abstract methods mean function without a body. In other words, abstract methods will not have any implementation.

So if we try to create an object for an abstract class there is a possibility to call abstract methods which makes no sense.

Secondly, abstract class by default will have a protected constructor means allowing the derived types to initialize it.

So it is against the base rules, If we create an object for Abstract Class in C# it will throw you a compilation error. It is the job of the subclasses to implement the abstract methods.

The basic rules need to remember about the abstract classes

  • An abstract class cannot be instantiated.
  • An abstract class may contain abstract methods and accessors.
  • It is not possible to modify an abstract class with the sealed modifier, which means that the class cannot be inherited.
  • A non-abstract class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors.

Hope you understand the reason behind, Why can’t we create an object for Abstract Class in C#. Make sure you remember the above important and crucial points before you create an abstract class.