OOP-Object Orientated Programming Flashcards
What are the benefits of OOP?
Data and functions combined, better modularity, low coupling, easier to re-use and closely modelling to the real-world.
What are the four pillars of OOP?
Abstraction, Encapsulation, Inheritance, Polymorphism
What is Polymorphism
Polymorphism is the ability of objects of different types to provide a unique interface for different implementations of methods.
What is Inheritance?
It is a mechanism where you can derive a from another class for a hierarchy of classes that share a set of attributes and methods.
What is Encapsulation?
The idea of restricting access to the methods in the class. Hiding it’s data by using properties {get; set;} or declare fields/variables as private.
What is abstraction?
The main goal is to handle complexity by hiding unnecessary details from the user. It achieved with either abstract classes or interfaces
What is a struct?
It’s is a user-defined data type that can store multiple related items. Structs are similar to classes used in object oriented programming
What is the difference between a struct and class
Structs are value types whereas Classes are reference types.
What is a backing field?
Properties use backing fields automatically to get and set. A backing field is therefore implicitly hidden. If you want to put logic in your properties, then you have to explicitly state them beforehand.
What is object initialisation?
A way to initialise an object of a class or collection. Object initialisers allow you to assign values to the fields or properties at the time of creating an without invoking a constructor.
What does the static keyword mean?
Static means that the particular member belongs to a type itself, rather than to an instance of that type.
What is an abstract method? An abstract class?
Abstract classes cannot be instantiated, but they can be subclassed. An abstract method is a method that is declared without an implementation.
What is an interface?
An interface is a completely abstract class which can only contain abstract methods and properties.
What is a C# property?
A property is a member that provides a flexible mechanism to read, write, or compute the value of a private field.
What does a constructor do?
It is used to initialise and set default values for the data member of the new object from a class.