samedi 23 septembre 2023

Facade Design Pattern With Possible Use Cases

Recently I was interviewed and discussed a bit on the design pattern Facade with the interviewer. My understanding on this in terms of C# is - There will be a base class library under which each facade or classes would be isolated with it's functionalities. Something as follows:

public class Facade
{
    public Facade()
    {
 
    }
    
    public void MethodA()
    {
        Console.WriteLine("Method A");
    }
 }

Interestingly the interviewer asked me if there are two different forms say Customer Registration and Order form, in that case will there be one Facade or two? What I said and in my opinion, there would be different facades and under the class library there would be two different facades or classes as those are two different features to be implemented. So my code snippet was something as follows:

Facade1:

public class Facade1
{
    public Facade1()
    {
 
    }
    
    public void AddCustomer()
    {

    }

    public void GetCustomer()
    {

    }
}

Facade2:

public class Facade2
{
    public Facade2()
    {
 
    }
    
    public void AddOrder()
    {

    }

    public void GetOrder()
    {

    }
}

Though the interviewer didn't ask me anything after showing the code snippet. But my question is the approach I did, is it the convenient one? After getting through an hour of session, I was thinking on the design pattern as I had a little experience on that and was wondering it was correct enough to provide the above example. Any clarification would be much appreciated.

Aucun commentaire:

Enregistrer un commentaire