- Published on
What are the different types of ๐ฐ๐น๐ฎ๐๐๐ฒ๐ inย .NETย ?
- Authors
- Name
- Muhammad Mustafa
A class is a blueprint for objects in the digital world. It defines their qualities (properties) and actions (methods) for members of the class.
๐๐ฏ๐๐๐ฟ๐ฎ๐ฐ๐ ๐จ:
A class that represents a contact for other classes that inherits from and provides common definition and implementation.ย
- It Cannot be instantiated. Can only be inherited.
- It Contains both abstract and non-abstract methods.
- A non-abstract class that inherits from an abstract class must implement all inherited abstract methods.
๐จ๐๐ฒ ๐๐ฎ๐๐ฒ: If we're defining multiple types of printers (Color Printer, Black and White Printer, etc). They are all in essence a Printer, they share some qualities and function. They all can Print() but each has different mechanism.ย So every type of printer will inherit Abstract Printer and provide their own implementation.
๐ฆ๐ฒ๐ฎ๐น๐ฒ๐ฑ ๐: The opposite of ๐๐ฏ๐๐๐ฟ๐ฎ๐ฐ๐. They are used to prevent other classes from extending or modifying behavior.
๐จ๐๐ฒ ๐๐ฎ๐๐ฒ: The sealed keyword tells the CLR that there is no class further down to look for methods, and that can improve performance.
๐ฃ๐ฎ๐ฟ๐๐ถ๐ฎ๐น ๐งฉ:ย
A class that could be divided into multiple pieces in different files. It allows dividing a class's properties and methods into multiple source files that are later compiled into a single file.
- If you seal a specific part of a partial class then the entire class is sealed.
- If a partial class is meant to be a base class, all of its parts collectively represent the base class.
๐จ๐๐ฒ ๐๐ฎ๐๐ฒ:
- Multiple developers can work on the same class easily.ย
- Partials could implement different interfaces in separate files.ย
- This could be used in a Feature Driven Design where we want to limit a feature inside its own boundaries but still use functionality from outside.
๐ฆ๐๐ฎ๐๐ถ๐ฐ:ย
A class that can't be instantiated, and its members are called directly using the class name.
๐จ๐๐ฒ ๐๐ฎ๐๐ฒ:
- They can be used for Extension Methods, Constants, Configuration and Common Functionality (Similar to Math Library)ย
- They used to be used to create a Singleton implementation but it's better to use the Dependency Injection Container.
๐๐ป๐ผ๐ป๐๐บ๐ผ๐๐ ๐ญ:ย
A class that closely resembles a JavaScript object, a dynamic type.
Var object = new {Name: "Unknown", Age: 25}ย
๐จ๐๐ฒ ๐๐ฎ๐๐ฒ: They are often used in LINQ queries or when returning ad-hoc data from methods.