Q37. Explain DIP, Dependency Inversion Principle with example?
Q38. What is Static keyword in C#?
Q40. Explain cycle of Garbage collector.
-------------------------------------------------------------------------------------------------------------------------
Q36. Explain LSP, Liskov substitution principle with example?
Answer:
Liskov Substitution Principle:
- Derived types must be completely substitutable for their base types.
- It is extension of Open Close Principle.
- Basically, any child class should be able to do anything the parent can do.
Implementation guidelines
- No new exceptions can be thrown by the subtype.
- Clients should not known which specific subtype they are calling.
- New derived classes just extend without replacing the functionality of old classes.
this is the same example of concept B() = new D();
https://youtu.be/gnKx1RW_2Rk
-------------------------------------------------------------------------------------------------------------------------
Q37. Explain DIP, Dependency Inversion Principle with example?
Answer:
Dependency Inversion Principle: (DIP)
High level modules should not depend on low level modules, but both should depend on abstraction.
Abstraction should not depend on details, but details should depend on abstractions.
Adaptor design pattern is an example of DIP.
https://youtu.be/5WHKNOTqwsA
-------------------------------------------------------------------------------------------------------------------------
Q38. What is Static keyword in C#?
Answer:
The static keyword in C# language is used to declare static classes, static class members , static properties and even static constructor.
- Static class contain only static variables, static methods and static constructor.
- Object cannot be created for static class.
- Static class are sealed class means you cannot inherit static class from another class.
- Data members of static class can be directly accessed by using its class name.
- Static class and its members remain available till the lifetime of application.
- Non-Static class can have one or more static members and properties
- Static properties or fields of a non-static class is shared across all the instances. So, changes done by one instance would reflect in others.
- Static methods can be called without creating an object. You cannot call static methods using an object of the non-static class.
- The static methods can only call other static methods and access static members. You cannot access non-static members of the class in the static methods.
- A non-static class can have both static and non-static constructor. Static constructor would be called once during the application starting but we can keep on calling non static constructor as much we want.
Q39. What is IOC design principle?
-------------------------------------------------------------------------------------------------------------------------
- When the system runs out of physical memory.
- When the GC.Collect method is called manually.
- When allocated objects in memory need more space
Generation 0: When an object is allocated on the heap, it belongs to generation 0. It is the young generation, which contains short-lived objects like temporary variables. If newly allocated objects are larger in size, they will go on the large object heap in a generation 2 collection. GC occurs mostly in generation 0.
Generation 1: When objects survive from a garbage collection of generation 0, they go to generation 1. Objects in generation 1 serve as a buffer between short-lived and long-lived objects.
Generation 2: When objects survive from a garbage collection of generation 1, they go to generation 2. Objects in generation 2 serve as long-lived objects. If objects still survived in generation 2, they remain in generation 2 till they’re alive.
No comments:
Post a Comment