muslimasfen.blogg.se

Oops interview questions
Oops interview questions







oops interview questions

How you can use them to write better code?Ĭohesion is the degree to which the various parts of a software component are related.Ĭoupling is defined as the level of inter dependency between various software components. We could have simply create one more constructor, but having a static method with meaningful name give a clear idea to the user of this class. Return new Complex(realnumber, imaginaryNumber) Īs you can see in the above code snippet, I wanted to have two constructors to my Complex class. Public static Complex FromRealNumer(int realnumber, int imaginaryNumber) Private Complex(int realnumber, int imaginaryNumber)

Oops interview questions full#

It can be specifically be use full in scenario where you want to have overloads of the constructor. What do you think can be use and utilization of public static factory method in a class?Ī public static factory method can be used to create an instance of the class. I have already discussed association, aggregation and composition in OOP here in one of my article.ġ0. What is association, aggregation and composition?

oops interview questions

Private static readonly Singleton singleton = new Singleton() The code for same is shown in below snippet. And hence the threading scenarios will be taken care by CLR. And since the field is static, the instance will be created by the CLR. The field will contain the instance of the Singleton class. The best way to create a thread safe singleton class without using a lock is to have a static field. How can you create a thread safe singleton class without using lock. In this article I have clear explained the two concepts. You can read more about abstraction and encapsulation in this article. Is the abstract class same as abstraction in C#? What is abstraction and encapsulation in OOP.









Oops interview questions