Solved

Posted on 2012-08-28
Medium Priority
495 Views
Hi

Is custom control an example of facade design pattern because if the developer is using the control then he is using the front end of the complex control.

Regards
Karan Gupta
0
Question by:KaranGupta
• 5
• 5

LVL 75

Expert Comment

ID: 38340574
Perhaps slightly, but I would tend to say no. The Facade pattern is about turning complex functionality into simple functionality. An example from a book I am reading describes an entertainment system. The complex system allows you to watch a movie, but you have to turn on each component:

turn_on_projector
turn_on_surround_sound
turn_on_dvd_player
start_popcorn_machine

With the Facade, you turn all of these steps into a more simple series of steps:

start_movie

...behind the scenes, the Facade is doing all the things you would have previously done yourself (above).
0

Author Comment

ID: 38340584
Hi Kaufmed

Thanks for the reply. Can you please give me some real time example related to programming?

Regards
Karan Gupta
0

LVL 75

Expert Comment

ID: 38343795
You can find a pretty decent example here:

0

Author Comment

ID: 38344168
Hi Kaufmed

Thanks for the reply. I got the answer. But one more thing if I create a system that will calculate tax is also an example of facade design pattern.

Regards
Karan Gupta
0

LVL 75

Accepted Solution

käµfm³d   👽 earned 2000 total points
ID: 38348186
The facade pattern is almost like two systems:  one system which houses all of the functionality, and a second system which encapsulates the first and makes it simpler. To answer your question:  it depends on how you write the code. If you simply write a class which calculates tax:

``````public class TaxCalculator
{
public decimal CalculateCountySalesTax(decimal value)
{
return 0.002M * value;
}

public decimal CalculateStateSalesTax(decimal value)
{
return 0.075M * value;
}

public decimal CalculateFederalSalesTax(decimal value)
{
return 0.001M * value;
}
}

public class Program
{
public static void Main()
{
TaxCalculator calculator = new TaxCalculator();
decimal saleAmount = 10.0M;
decimal countyTax = calculator.CalculateCountySalesTax(saleAmount);
decimal stateTax = calculator.CalculateStateSalesTax(saleAmount);
decimal federalTax = calculator.CalculateFederalSalesTax(saleAmount);
decimal total = saleAmount + countyTax + stateTax + countyTax;
}
}
``````

...then no, that would not be a facade. Instead of having calling code make all of those individual calls to calculate each level of tax, you can make it simpler to use by incorporating a facade:

``````public class TaxCalculator
{
public decimal CalculateCountySalesTax(decimal value)
{
return 0.002M * value;
}

public decimal CalculateStateSalesTax(decimal value)
{
return 0.075M * value;
}

public decimal CalculateFederalSalesTax(decimal value)
{
return 0.001M * value;
}
}

{
private TaxCalculator _calculator;

{
this._calculator = new TaxCalculator();
}

public decimal CalculateTaxes(decimal value)
{
decimal tax = 0M;

tax += this._calculator.CalculateCountySalesTax(value);
tax += this._calculator.CalculateStateSalesTax(value);
tax += this._calculator.CalculateFederalSalesTax(value);

return tax;
}
}

public class Program
{
public static void Main()
{
decimal saleAmount = 10.0M;
decimal tax = calculator.CalculateTaxes(saleAmount);
decimal total = saleAmount + tax;
}
}
``````
0

Author Comment

ID: 38363204
I've requested that this question be closed as follows:

Accepted answer: 0 points for KaranGupta's comment #a38344168

for the following reason:

Got the explanation
0

LVL 75

Expert Comment

ID: 38363205
Which is... your own comment? Care to elaborate?
0

Author Comment

ID: 38363213
Hi Kaufmed

I selected your post as answer, but I don't know how it went to the close question work flow. I am accepting it again :)
0

Author Closing Comment

ID: 38363215
0

LVL 75

Expert Comment

ID: 38363228
No problem. I was just a bit confused for the moment  = )
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
###### Suggested Courses
Course of the Month16 days, 19 hours left to enroll