There are Partial,abstract,static,sealed and instance classes in c#.
Partial Class: Partial class is useful when the class functionality is too big (i.e when number of lines of code in the class is too big) and when a developer want to share some of the functionalities with other developers this is useful.
Sealed Class : when the class is functionality is complete and you don’t want to allow any other class to extend your class,then you need to declare your class as sealed. No other Class can extend or use your sealed class as base class.
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. In the abstract class you can have 0 or more abstract methods,properties and along with implemented methods. You cannot create an instance to the Abstract Class.And also if you have family of related classes and all those classes having some common functionality try pushing then into a common base class. this way you will get code re-usability and can get easy maintainability.
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. Advantage with static class is “Object instantiation overhead is reduced”.And this class always have single memory location where in every other class will hit the same memory location. If class A changed some data in static class , Changed data is available to every other subsequent classes who access the static class.
No comments:
Post a Comment