samedi 18 janvier 2020

Complete the missing codes in class

Someone asked me to complete the bellow code which I don't understand properly. I guess the first problem is about factory pattern and second problem is on anonymous function problem.

You are writing a construction game, you want to let the user configure as many things as they want, with any order. Your boss comes up with a code that let the user add and configure as many things as they want. But it will build the building when the user call the “.Build()”. Here is the code:

private static void Main(string[] args)
{
    var myHouse = new Building()
      .AddKitchen()
      .AddBedroom("master")
      .AddBedroom("guest")
      .AddBalcony();

var normalHouse= myHouse.Build();

//kitchen, master room, guest room, balcony
Console.WriteLine(normalHouse.Describe());

myHouse.AddKitchen().AddBedroom("another");

var luxuryHouse = myHouse.Build();

//it only shows the kitchen after build
//kitchen, master room, guest room, balcony, kitchen, another room
Console.WriteLine(luxuryHouse.Describe());

}

enter image description here

Your team is creating a home management system for Alexa, they want to be able to configure Alexa settings through the code. your boss passes you this code and ask you to complete it.

private static void Main(string[] args)
{
var alexa = new Alexa();
Console.WriteLine(alexa.Talk()); //print hello, i am Alexa

alexa.Configure(x =>
{
    x.GreetingMessage = "Hello {OwnerName}, I'm at your service";
    x.OwnerName = "Bob Marley";
});

Console.WriteLine(alexa.Talk()); //print Hello Bob Marley, I'm at your service

Console.WriteLine("press any key to exit ...");
Console.ReadKey();

} enter image description here

Aucun commentaire:

Enregistrer un commentaire