Facade Pattern
Author: Deron Eriksson
Description: This Java tutorial describes the facade pattern, a structural design pattern.
Tutorial created using: Windows Vista || JDK 1.6.0_11 || Eclipse JEE Ganymede SR1 (Eclipse 3.4.1)

Page: < 1 2

(Continued from page 1)

The FacadeDemo class contains our client code. It creates a Facade object and then calls its three methods with a parameter value of 3. It displays the returned results.


package com.cakes;

public class FacadeDemo {

	public static void main(String[] args) {

		Facade facade = new Facade();

		int x = 3;
		System.out.println("Cube of " + x + ":" + facade.cubeX(3));
		System.out.println("Cube of " + x + " times 2:" + facade.cubeXTimes2(3));
		System.out.println(x + " to sixth power times 2:" + facade.xToSixthPowerTimes2(3));



The console output of the execution of FacadeDemo is shown here.

Console Output

Cube of 3:27
Cube of 3 times 2:54
3 to sixth power times 2:1458

This example demonstrates how the facade pattern can be used to simplify interactions with a system of classes by providing a single point of interaction with the subsystem and hiding the complex details of subsystem interactions from client code. This is accomplished with a Facade class.

Page: < 1 2

Related Tutorials: