Tech Questions Flashcards
OOP Pillers
Object Oriented Programming
- Abstraction: Only essential/necessary features of an entity/object to outside world
- Encapsulation: Wrapping data up and member function together into a singe unit class.
- Inheritance: Ability to create a new class from existing class. Aquire properties.
- Polymorphism: Many forms, subclass can define its own unique behavior and still share functions.
Advantages of Inheritance
- Helps to reuse, customize, and enhance the existing code.
- Helps write a code accurately and reduce the development time.
- Reusability
- Reduces Redundancy
- Reduces source code size -> Improves readability
SOLID
Single-responsibility principle: A class should only have a single responsibility, that is, only changes to one part of the software’s specification should be able to affect the specification of the class.
Open–closed principle: “Software entities … should be open for extension, but closed for modification.”
Liskov substitution principle: “Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.” See also design by contract.
Interface segregation principle: “Many client-specific interfaces are better than one general-purpose interface.”
Dependency inversion principle: One should “depend upon abstractions, [not] concretions.”
C# Multiple Class Inheritance
In Multiple inheritance, one class can have more than one superclass and inherit features from all its parent classes. As shown in the below diagram, class C inherits the features of class A and B.
But C# does not support multiple class inheritance. To overcome this problem we use interfaces to achieve multiple class inheritance. With the help of the interface, class C( as shown in the above diagram) can get the features of class A and B.
What is the difference between interfaces and classes?
Class
- A class describes the attributes and behaviors of an object
- A class may contain abstract methods, concrete methods
- Members of a class can be public, private, protected of default
Interface
- An interface contains behaviors that a class implements
- An interface contains only abstract methods
- All the members of the interface are public by default
What is the difference between public, static, and void?
All access modifiers
Public- This is the access specifier that states that the method can be accesses publicly
static- the object is not required to access static members
void- The method doesn’t return any value
main- entry point of a C# program
What are namespaces and how are they used?
A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.
What is method overloading?
a feature that allows a class to have more than one method having the same name, if their argument lists are different. It is similar to constructor overloading in Java, that allows a class to have more than one constructor having different argument lists.
What is method overriding?
Overriding is a feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super-classes or parent classes. When a method in a subclass has the same name, same parameters or signature, and same return type(or sub-type) as a method in its super-class, then the method in the subclass is said to override the method in the super-class.
https://www.geeksforgeeks.org/overriding-in-java/
What are access modifiers?
All types and type members have an accessibility level. The accessibility level controls whether they can be used from other code in your assembly or other assemblies. Use the following access modifiers to specify the accessibility of a type or member when you declare it:
public: The type or member can be accessed by any other code in the same assembly or another assembly that references it.
private: The type or member can be accessed only by code in the same class or struct.
protected: The type or member can be accessed only by code in the same class, or in a class that is derived from that class.
internal: The type or member can be accessed by any code in the same assembly, but not from another assembly.
protected internal: The type or member can be accessed by any code in the assembly in which it’s declared, or from within a derived class in another assembly.
private protected: The type or member can be accessed only within its declaring assembly, by code in the same class or in a type that is derived from that class.
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers
What is the difference between abstract and virtual?
Virtual methods have an implementation and provide the derived classes with the option of overriding it.
Abstract methods do not provide an implementation and force the derived classes to override the method.
So, abstract methods have no actual code in them, and subclasses HAVE TO override the method.
Explain Dependency Injection?
In software engineering, dependency injection is a technique in which an object receives other objects that it depends on. These other objects are called dependencies. … The “injection” refers to the passing of a dependency (a service) into the object (a client) that would use it.
What is the difference between a List and an Array ?
The main difference between these two data types is the operation you can perform on them. Arrays are specially optimised for arithmetic computations so if you’re going to perform similar operations you should consider using an array instead of a list.
What is an IEnumerable ?
IEnumerable is an interface defining a single method GetEnumerator() that returns an IEnumerator interface. It is the base interface for all non-generic collections that can be enumerated. This works for read-only access to a collection that implements that IEnumerable can be used with a foreach statement.
What is the difference between a while loop and do while loop ?
Here, the main difference between a while loop and do while loop is that while loop check condition before iteration of the loop. On the other hand, the do-while loop verifies the condition after the execution of the statements inside the loop.
Furthermore, the while loop is known as the entry-controlled loop. Conversely, the do while loop is called the exit controlled loop. In this article, we are going to discuss the differences between “while” loop and “do-while” loop.
What is an Enum ?
An enum is a special “class” that represents a group of constants (unchangeable/read-only variables).
What are Properties ?
A property is a member that provides a flexible mechanism to read, write, or compute the value of a private field. Properties can be used as if they are public data members, but they are actually special methods called accessors. This enables data to be accessed easily and still helps promote the safety and flexibility of methods.
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties
What is a constructor?
Whenever a class or struct is created, its constructor is called. A class or struct may have multiple constructors that take different arguments. Constructors enable the programmer to set default values, limit instantiation, and write code that is flexible and easy to read. For more information and examples, see Using Constructors and Instance Constructors.
Can you explain the MVC pattern ?
The Model View Controller (MVC) design pattern specifies that an application consist of a data model, presentation information, and control information. The pattern requires that each of these be separated into different objects. MVC is more of an architectural pattern, but not for complete application
What is an ORM ?
Object-relational-mapping is the idea of being able to write queries like the one above, as well as much more complicated ones, using the object-oriented paradigm of your preferred programming language.
Long story short, we are trying to interact with our database using our language of choice instead of SQL.
Can you explain the difference between IEnumerable and IQuerable ?
Querying data from a database, IEnumerable execute a select query on the server side, load data in-memory on a client-side and then filter data. Querying data from a database, IQueryable execute the select query on the server side with all filters. IEnumerable Extension methods take functional objects
What is LINQ ?
Language-Integrated Query (LINQ) is the name for a set of technologies based on the integration of query capabilities directly into the C# language. Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support.
Can you describe the difference between a reference type and a value type ?
Value Type:
A Value Type stores its contents in memory allocated on the stack. When you created a Value Type, a single space in memory is allocated to store the value and that variable directly holds a value. If you assign it to another variable, the value is copied directly and both variables work independently. Predefined datatypes, structures, enums are also value types, and work in the same way. Value types can be created at compile time and Stored in stack memory, because of this, Garbage collector can’t access the stack.
Reference Type:
Reference Types are used by a reference which holds a reference (address) to the object but not the object itself. Because reference types represent the address of the variable rather than the data itself, assigning a reference variable to another doesn’t copy the data. Instead it creates a second copy of the reference, which refers to the same location of the heap as the original value. Reference Type variables are stored in a different area of memory called the heap. This means that when a reference type variable is no longer used, it can be marked for garbage collection. Examples of reference types are Classes, Objects, Arrays, Indexers, Interfaces etc.
What is an object ?
An object is basically a block of memory that has been allocated and configured according to the blueprint. A program may create many objects of the same class. Objects are also called instances, and they can be stored in either a named variable or in an array or collection.