.Net Deck 3 Flashcards
What are C# extension methods?
Extension methods, as the name suggests, are additional methods. Extension methods allow you to inject additional methods without modifying, deriving or recompiling the original class, struct or interface. Extension methods can be added to your own custom class, .NET framework classes, or third party classes or interfaces.
What are Interfaces?
A type definition similar to a class, except that it purely represents a contract between an object and its user. It can neither be directly instantiated as an object, nor can data members be defined. So, an interface is nothing but a collection of method and property declarations.
An interface contains definitions for a group of related functionalities that a class or a struct can implement. By using interfaces, you can, for example, include behavior from multiple sources in a class. That capability is important in C# because the language doesn’t support multiple inheritance of classes.
What is an abstract class and is this different than an interface?
An abstract class allows you to create functionality that subclasses can implement or override. An interface only allows you to define functionality, not implement it. And whereas a class can extend only one abstract class, it can take advantage of multiple interfaces
Can you create an instance of an abstract class?
you cannot create an instance of an abstract class with the new keyword.
What is inheritance?
Inheritance is one of the fundamental attributes of object-oriented programming. It allows you to define a child class that reuses (inherits), extends, or modifies the behavior of a parent class.
What are the principles of object oriented programming?
Encapsulation - Mechanism of hiding of data implementation by restricting access to public methods. Instance variables are kept private and accessor methods are made public to achieve this.
Abstract - Concept or an Idea which is not associated with any particular instance. one class should not know the inner details of another in order to use it, just knowing the interfaces should be good enough.
Inheritances - Expresses “is-a” and/or “has-a” relationship between two objects. Using Inheritance, In derived classes we can reuse the code of existing super classes. based on class inheritance (using extends) or interface implementation (using implements).
Polymorphism - One name many forms. It is further of two types — static and dynamic. Static polymorphism is achieved using method overloading and dynamic polymorphism using method overriding.
Write out an example class diagram (a diagram showing how several classes are related) for the objects described description
Include Classes for:
- Base person class
- Employee class
- Manager class
- Robot class
Include an interfaces for:
- “People”
- “Robots”
- An interface that both implement
Include an example of an abstract method and an abstract class
Be sure to have an example of how you leverage inheritance
What are Generics in .Net
Generics are classes, structures, interfaces, and methods that have placeholders (type parameters) for one or more of the types that they store or use.
Why are Generics so important?
Generics in C# is its most powerful feature. It allows you to define the type-safe data structures. This out-turn in a remarkable performance boost and high-grade code, because it helps to reuse data processing algorithms without replicating type-specific cod
What is IEnumerable and what significance does it hold?
IEnumerable is an interface that allows you to loop over an entire collection.