Class in C#

Class is a template which defines the state and Behavior of Objects.

A class represents a set of objects that share a common structure and a common behavior- Grady Booch's.

Class is composed of three things: a name, attributes, and operations.

Type of Class supported by dotnet.

  • Partial
  • Abstract
  • Static
  • Sealed
  • Instance

Abstract Class: When the developer/programmer don't know the functionality of the class fully and , you want to leave the implementation to the derived classes , then use the Abstract class

Sealed Class: when the class is functionality is complete and you don't want to allow any other class to extend your class

Static Class: when any class is most frequently used or if any class is qualified as helper class( helper class is one which will be repeatedly used by all other classes) then try using Static Class

According to Object Oriented Design Principles, there are five principles that you must follow when design a class,

SRP - The Single Responsibility Principle – A class should have one, and only one, reason to change.

OCP - The Open Closed Principle – You should be able to extend a classes behavior, without modifying it.

LSP - The Liskov Substitution Principle- Derived classes must be substitutable for their base classes.

DIP - The Dependency Inversion Principle- Depend on abstractions, not on concretions.

ISP - The Interface Segregation Principle- Make fine grained interfaces that are client specific.

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now