Translation Tipatterns - Reducing Interface Complexity

xiaoxiao2021-03-06  84

Reduce interface complexity (Reducing Interface Complexity)

Sometimes you need to solve very simple questions, such as "The current interface is not you needed." The Façade mode (extempore) provides an interface to a series of classes for a series of classes for a series of users.

Appearance Façade When I want to find a method to try to convert the demand preliminary (first-cut), the principle I usually use is: "All ugly things are hidden into the object". Basically, Façade is doing this. If you have a bunch of people who make people dizziness and interactions? And they are not a client-side programmer must understand, then you can create an interface for client programmers only with those necessary features. Façade mode is often implemented as an abstract factory that conforms to the Singleton mode. Of course, you can achieve the above effects by creating classes containing static factory methods.

//: facade.javaPackage facade; import junit.framework. *; class a {public a (int x) {}} class b {public b (long x) {}} class c {public c (Double X) {}} //}} That aren't exposed // by the facade go here ... public class facade extends testcase {static a makea (int x) {return new a (x);} static b makeb (long x ) {RETURN NEW B (X);} static c makec (double x) {return new c (x);} public void test () {// the client programmer gets the Objects // by calling the static methods: a a = Facade.makea (1); b = facade.makeb (1); c = facade.makec (1.0);} public static void main (string args []) {junit.textui.teStrunner.run (Facade). Class);}} / //: ~

The example given by "design mode" is to use another class in a class (to implement façade mode). Tax advisers are façade between you and tax codes, and he is also a middleman between you and the tax system.

Package I feel as façade variants, façade is more inclined to "procedural", which is non-object-oriented: You get an object by calling some functions. How big is it and Abstract Factory? The key of the façade model is to hide a class of libraries (and their interaction) so that they are not visible to the client, so that the interfaces of those classes are more concise and easy to understand. In fact, this is also a matter of Java's packaging feature: Outside the library, you can only create and use those classes that are declared as public (public), only the same as the same Package class. It seems that Façade seems to be a function of Java embedded. To be fair, "design mode" is mainly written to C readers. Although C has a NameSpaces mechanism to prevent conflicts between global variables and class names, it does not provide a hidden mechanism, and in Java you can implement this by declaring the Non-Public class. I think that in most cases, Java's package feature is enough to solve the problem of Façade mode. table of Contents

转载请注明原文地址:https://www.9cbs.com/read-121899.html

New Post(0)