** Table of Contents ** When a client uses a subsystem, it is a pattern that combines complicated interfaces into only the minimum required interfaces. If you do not want to customize the subsystem, make it easier to use by focusing only on the interface to which the Facade pattern is applied.
The point is to weaken the coupling between the client and the subsystem. It is easy to change the subsystem because the coupling is weak.
Give one unified interface to multiple interfaces existing in the subsystem. The Facade pattern defines a high-level interface that facilitates the use of subsystems.
-A class that defines the minimum interface required for Facade clients to use subsystems. -Classes in the subsystem The subsystem to be used
I wonder why only the classes in the subsystem among the components are not properly named ...
Just create a new window, but write sample code.
Various printer class interfaces
Printer.kt
package facade
class Printer {
fun startUp() { print("Start-up") }
fun shutDown() { print("End") }
fun setToner(color: String) { print("Toner${color}Set to color.") }
fun addPaper(num: Int) { print("Paper${num}I will add one.") }
fun login(name: String) { print("User${name}Has logged in.") }
fun printOut(num: Int) { print("${num}Print a sheet.") }
}
Since all the client needs to operate the printer is to print, we will prepare a window for that.
Limited interface
FacadePrinter.kt
package facade
class FacadePrinter {
private val printer = Printer()
fun printOut(num: Int) {
printer.printOut(num)
}
}
Client.kt
package facade
class Client {
init {
val printer = FacadePrinter()
printer.printOut(15)
//No other method available
// printer.startUp()
// pritner.shutDown()
}
}
The result is not so big
[output]
Print 15 sheets.
Somehow, I feel that my perception is wrong. Please point out in the comments.
Recommended Posts