OOP is, by far, the most common programming paradigm used in the IT industry. All the major programming languages now support OOP including C#. OOP reflects the real world behavior of how things work and the most efficient way to model and organize very large applications.
Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and speeds up implementation time.
When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class.
The idea of inheritance implements the IS-A relationship. For example, mammal IS A animal, dog IS-A mammal hence dog IS-A animal as well, and so on.
OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object is created in the program to represent a class. Therefore, an object encapsulates all the features, such as data and behavior that are associated to a class. OOP allows developers to develop modular programs and assemble them as software. Objects are used to access data and behaviors of different software modules, such as classes, namespaces, and sharable assemblies. .NET Framework supports only OOP languages, such as Visual Basic .NET, Visual C#, and Visual C++.
Constructor is a special method of a class, which is called automatically when the instance of a class is created. It is created with the same name as the class and initializes all class members, whenever you access the class. The main features of a constructor are as follows:
Encapsulation is defined as the process of enclosing one or more items within a physical or logical package. Encapsulation, in object oriented programming methodology, prevents access to implementation details.
The word polymorphism means having many forms. In object-oriented programming paradigm, polymorphism is often expressed as one interface, multiple functions.
Procedural programming is based upon the modular approach in which the larger programs are broken into procedures. Each procedure is a set of instructions that are executed one after another. On the other hand, OOP is based upon objects. An object consists of various elements, such as methods and variables.
Access modifiers are not used in procedural programming, which implies that the entire data can be accessed freely anywhere in the program. In OOP, you can specify the scope of a particular data by using access modifiers - public, private, internal, protected, and protected internal.
class and a structure?Class:
nullStructure:
null valuesclass and an object?A class acts as a blue-print that defines the properties, states, and behaviors that are common to a number of objects. An object is an instance of the class. For example, you have a class called Vehicle and Car is the object of that class. You can create any number of objects for the class named Vehicle, such as Van, Truck, and Auto.
The new operator is used to create an object of a class. When an object of a class is instantiated, the system allocates memory for every data member that is present in the class.
virtual keyword used in code?The virtual keyword is used while defining a class to specify that the methods and the properties of that class can be overridden in derived classes.
All the methods inside an interface are always public, by default. You cannot specify any other access modifier for them.
You can prevent a class from overriding in C# by using the sealed keyword.
overriding different from method overloading?No, a class cannot inherit the constructor of its base class.
class and a structure?The following are some of the similarities between a class and a structure:
Both structures and classes can have delegates and events.
abstract classes? What are the distinct characteristics of an abstract class?An abstract class is a class that cannot be instantiated and is always used as a base class. The following are the characteristics of an abstract class:
The basic purpose of an abstract class is to provide a common definition of the base class that multiple derived classes can share.
Data encapsulation is a concept of binding data and code in single unit called object and hiding all the implementation details of a class from the user. It prevents unauthorized access of data and restricts the user to use the necessary data only.
Polymorphism describes a pattern in object-oriented programming in which classes have different functionality while sharing a common interface.
The beauty of polymorphism is that the code working with the different classes does not need to know which class it uses since they’re all used the same way. A real-world analogy for the polymorphism is a button. Everyone knows how to use a button: you simply apply pressure to it. What a button “does,” however, depends on what it is connected to and the context in which it is used — but the result does not affect how it is used. If your boss tells you to press a button, you already have all the information needed to perform the task.
struct instead of a class?Do not define a structure unless the type has all of the following characteristics:
static if the original method is not static?abstract class and an interfaceabstract class?static constructor?get and set - instead of simply using public fields for those variables?private class in a namespace?monad?Rust has been Stack Overflow’s most loved language for four years in a row and emerged as a compelling language choice for both backend and system developers, offering a unique combination of memory safety, performance, concurrency without Data races...
Clean Architecture provides a clear and modular structure for building software systems, separating business rules from implementation details. It promotes maintainability by allowing for easier updates and changes to specific components without affe...
Azure Service Bus is a crucial component for Azure cloud developers as it provides reliable and scalable messaging capabilities. It enables decoupled communication between different components of a distributed system, promoting flexibility and resili...