Skip to main content

Features Of Abstract Class

Features of Abstract Class


    An abstract class cannot be instantiated.

    An abstract class contain abstract members as well as non-abstract members.

    An abstract class cannot be a sealed class because the sealed modifier prevents a class from being inherited and the abstract modifier requires a class to be inherited.

    A non-abstract class which is derived from an abstract class must include actual implementations of all the abstract members of parent abstract class.

    An abstract class can be inherited from a class and one or more interfaces.

    An Abstract class can has access modifiers like private, protected, internal with class members. But abstract members cannot have private access modifier.

    An Abstract class can has instance variables (like constants and fields).

    An abstract class can has constructors and destructor.

    An abstract method is implicitly a virtual method.

    Abstract properties behave like abstract methods.

    An abstract class cannot be inherited by structures.

    An abstract class cannot support multiple inheritance.

Common design guidelines for Abstract Class


    Don't define public constructors within abstract class. Since abstract class cannot be instantiate and constructors with public access modifiers provides visibility to the classes which can be instantiated.

    Define a protected or an internal constructor within an abstract class. Since a protected constructor allows the base class to do its own initialization when sub-classes are created and an internal constructor can be used to limit concrete implementations of the abstract class to the assembly which contains that class.

When to use


    Need to create multiple versions of your component since versioning is not a problem with abstract class. You can add properties or methods to an abstract class without breaking the code and all inheriting classes are automatically updated with the change.

    Need to to provide default behaviors as well as common behaviors that multiple derived classes can share and override.

Comments

Popular posts from this blog

Computer Science Defenition

Computer Science Computer science is the scientific and practical approach to computation and its applications. It is the systematic study of the feasibility, structure, expression, and mechanization of the methodical procedures (or algorithms ) that underlie the acquisition, representation, processing, storage, communication of, and access to information , whether such information is encoded as bits in a computer memory or transcribed in genes and protein structures in a biological cell . [1] A computer scientist specializes in the theory of computation and the design of computational system

Understanding machine learning

What is machine learning does?  It Finds patterns in data and uses those patterns to predict the future.          EXAMPLES :  Detecting credit card fraud : You can use machine learning  detect credit card fraud, Suppose you have data about previous credit card transactions. You could find patterns in that data potentially  that allows you to detect when a new credit card transaction is likely to be fraudulent. Determining whether a customer is likely to switch to a competitor :  You could possibly find the patterns in the existing customer data that will help you do that Lots more What does it mean to learn ? Yes it's something like your own learning process. You have learned reading,listening, walking everything by using your experience on it, the data you have in your mind and continuous improvements.  How did you learn to read? Well learning requires identifying patterns. Reading for instance you ...

Function pass by value vs. pass by reference

Function pass by value vs. pass by reference I will call what you are passing in a to a function the actual parameters, and where you receive them, the parameters in the function, the formal parameters. They are also called actual and formal arguments. When passing parameters, what it is called and what happens can be confusing. It is less essential that you call it the "correct" thing than you know exactly what is happening. It is critical to have a good mental model, a valid memory picture of the process. Recall that when you call a function, a chunk of memory called an activation record is allocated. Critical to the discussion here is that this memory holds the formal parameter values and function local variables. By definition, pass by value means you are making a copy in memory of the actual parameter's value that is passed in, a copy of the contents of the actual parameter. Use pass by value when when you are only "using" the paramet...