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.
What is the difference between method overloading and method overriding?
In method overloading, methods must the have the same name and different signatures. Method overriding it’s the same name and same signature.
How does C# support Encapsulation?
Properties, backing fields and methods.
What is the difference between a constructor and other methods?
Constructor is used to initialise an object whereas method is used to exhibit the function of an object.
What does the virtual keyword mean?
The virtual keyword is used to modify a method, property indexer, or event declaration and allow it to be overly in a derived class.
What does the sealed keyword mean?
It restricts classes or methods to be inherited by a subclass
What are the 5 solid principles?
Single responsibility principle Open/Closed principle Liskov Substitution principle Interface Segregation principle Dependency Inversion principle
What are the elements of a class?
Class name, type, fields, properties, methods, access modifiers(public, private, protected).
What properties and methods does the object class have?
Equals(),GetHashCode(),GetType(),ToString(), ReferenceEquals().
What is the single responsibility principle?
That an object/class should only have one responsibility and that it should be completely encapsulated by the class.
What is the open/closed principle?
An entity allows it’s behaviour to be extended but never by modifying it’s source code.
What is the Liskov Substitution principle?
That objects should be replaceable by instances of their subtypes and that without affecting the functioning of your system from a client’s point of view.
What is the Interface Segregation principle?
Large interfaces need to be split into smaller interface that are more specific.
What is Dependency Inversion principle?
High level modules should not depend on low level modules rather both should depend on abstraction. Abstraction should not depend on details; rather detail should depend on abstraction.