JAVA bridge mode

2010-03-29  来源:本站原创  分类:Java  人气:278 

1. From the Talking Tree

Basically, everyone knows that the concept of a tree.

Slightly go into. NET will understand the nature of,. NET has a object tree.

Learning ASP.NET, people would be aware, Web on a control tree.

Even if it is studied only the data structure to cope with the exam students will be aware of the concept of Tree.

2. The demand for expanded into a tree

To give our most commonly used Photoshop as an example.

In Photoshop, there are many graphical tools, such as stars, such as square, circular, and so is another example.

In Photoshop, the Needless to say, there are many colors to choose from.

And thus a red star, green star. The red square, green square and so on.

To see if the resulting tree:

JAVA bridge mode

It is three kinds of graphics, three kinds of colors, so we have a total of nine classes to the statement, of course, we have not the middle of the process of supporting the parent class.

If we are now 18 kinds of graphics, 12 colors, then we need to write 18 * 12 class, and then add 12 color classes and a general parent class, we need a total of 12 * 18 +12 +1 = 229 class.

Let us remember this figure.

Hope you will not and I bickering that we can write the color and dynamic incoming Color. We here assume that this property Color does not exist, but we need to achieve their own.

3. Object explosion

The word I have two design patterns mentioned.

At "Review the design pattern (1) - Flyweight" , I would use this word.

Of course, the explosion did not last article in the less terror.

But the search for the perfect and we should try to improve him.

Then let us begin to find solutions.

4. Multiple inheritance?

Learning C + +, I, the first thought is that multiple inheritance.

Description of this model with multiple inheritance re-fitting. Statement 18 graphics class, and then declare the 12 color categories, and then use a specific graphics class to multiple inheritance.

Let us look at this statement Chart:

JAVA bridge mode

Complex line may seem somewhat disorganized, but I think we should all understand what it means.

Understand the Dao Shi easy to understand, but this time we take another look at the number of this class:

Color 12 + Color parent class 1 + 18 + graphic graphic parent class 1 +12 * 18, this figure appears to be prior to that figure than our bigger.

Maybe I will argue for him said he was at the expense of space for readability, but the poor C # does not support multiple inheritance?

5. Multiple inheritance are being abandoned?

1. From the practical application of stress, B inherits A, and rewrite the method, C inherit A, and rewrite the method, then this time inherited the B and D over C, then whether he has inherited the method B or C methods?

2. From the object-oriented perspective, each class should be only one parent class, just like say that a person can only have one father.

However, multiple inheritance, after all, it is fairly easy for us, he is very easy to understand, like the segment, like the color and graphics.

Multiple inheritance away from the Java started on multiple inheritance problems left over from history, how they solve it?

Let our in-depth within the Java camp to explore the answer.

6. In-depth Java camp, to find the answers

Method 1: The interface to replace the inheritance that I am not interested, I used to know, I want to know something else.

Method 2: In fact, we use inheritance, it always had a succession of points, the main points and secondary succession. Then we should distinguish between primary and secondary, and then go to the main successor inherits that point, and then use AOP to solve the issue of secondary succession of points.

7. AOP + OOP == Complete OOP

AOP, aspect-oriented programming, also called aspect-oriented programming. Most of the design patterns are engaged in the relationship between the interface and the external, and rarely go deep inside the class to solve the problem. AOP is to solve this problem.

For example, we are doing the project, it is often necessary to record the log, then the level of the log is often distributed in various categories, but in fact this log function and the core functions of this class is not the nature of contact, which is actually contrary to the object The Single Responsibility Principle, and more importantly one of these scattered in all corners of the code, very easy to maintain.

AOP actually use a "cross-cutting" technology, in-depth within the object, and then a number of classes that affect the function of writing a module, and then injected into the various classes. In order to achieve the functional separation, it is often used for log management, security, control, secondary succession of points.

But I found a bit on the Internet, Microsoft officials did not provide a AOP framework of the technology, but are more sub-implementation framework, there is no Java, Spring of the class of widely used standards.

8. Next best thing

Spring's two key words: control inversion, dependency injection.

Since we can not rely on injection, then we are into the bar common.

So much nonsense, let us come to the question: bridge mode. First-come, simply Kanxia chart:

JAVA bridge mode

To explain, let us first take a look at the meaning of bridging modes: abstract and implementation of some parts of phase separation, so that they can change each other.

9. Code Evolution

Let me first explain that this model is probably thinking.

Continues to use the example above, do explain, according to bridge mode, we should change all the points to be detached from them, and then combined into a stable part. Look at the code bar.

class Program
    static void Main(string[] args)
        PhotoShop ps = new PhotoShop(new RedColor(),
 new Star());
interface IColor { }
class RedColor : IColor { }
class BlueColor : IColor { }
class YellowColor : IColor { }

interface IGraphics { }
class Rectangle:IGraphics { }
class Star:IGraphics { }
class Round : IGraphics { }

class PhotoShop
    IColor color;
    IGraphics graphics;
    public PhotoShop(IColor c, IGraphics g)
        this.color = c; = g;
    public void Draw()

JAVA bridge mode

The chart at this time should be like this:

JAVA bridge mode

This time let's calculate the total number of categories:

12 color categories +18 graphical class +1 = 31 of our graphics classes. Is very small?

10. Exploration of conceivable book, to trace the traceability

Earth had no road, walking too many people, but also became Rd.

In fact, there is no mode of this earth, but the principle of summing up, they have become models.

Model can be derived, but the principle is relatively stable, let us from this pattern to dig principles.

In the article at the beginning, we think of What are they? Three principles of object-oriented encapsulation inheritance polymorphism in the first one: inheritance. So the object caused an explosion. The Combination to solve this problem.

Still remember a very old-fashioned face examination questions, the difference between abstract classes and interfaces.

Then let us talk about from this side examination questions:

1. Interface is a behavior contract, which features an abstract class is an abstract. One can do, one is a.

2. Object-oriented design principles, said: combination of superior inheritance.

Okay, let's look at the second point, why is that combination is superior to the succession, not that it combined to replace the inheritance?

Let us continue to look downward.

11. Excellence

Combination is superior to the succession, rather than to replace the inherited form.

The above code, if required not only the color and shape, but also ask for more, then I am going on to write lots and lots of properties, good trouble.

But more importantly, if there is such a demand, I now have 12 kinds of colors, and then there are three kinds of shapes, namely square, circular and the stars, there are two kinds of pens, pencils and crayons, respectively. But now I only correspond to a square and the stars, a pencil, crayons only the corresponding circular and the stars. In other words there is no circular and square pencil crayons. In this case I am not a waste of a combination effect? And customers are possible combinations of mistaken?

JAVA bridge mode

Yes, do not blindly to consider combinations. Repeat once again that I love to say: mode is to change, not in order to mode model, we only need to be detached from a change-point can be a!

If so, then we written a stable sector, there are two options:

JAVA bridge mode

Or is to color as the parent class, this is to look at our personal choice.

Way down, as if to say there are many classes, but we are only a handful of choice, not our class less out?

12. There is a capability called the trade-off

This is what I <Javascript The return of the King > see, the original Web standards for HTML on the choice of follow on.

Here I would like to say, hard to bridge mode is not difficult in understanding, but rather difficult to apply. Difficult to extract out of us how to get to the change point, but retain our stable point.

That is the ability of the designer's choice!

13. Give a rather anti-3 - plant or not plant

Factory pattern, which I am sure that everyone is familiar.

Get rid of the ugly if-else, then use the factory to become independent class.

Respond to changes in the database, using the abstract factory + reflex + web.config to Gaoding different data access layer.

Respond to the different authentication methods, using factory + reflection.

It is almost become a common layer of Petshop of all things. However, in our project, really need the case?

First, by the if-else, where he was ugly, because once we have introduced a new logic conditions, we need to modify the source code to be recompiled.

And then the database and authentication, I think, with very few companies have really to modify the database and they are accustomed to the product authentication.

If so, that these are fixed, then we also necessary in order to model and model to go with the factory Mody?

14. Bridging Summary

Bridge mode (Bridge pattrern): abstract in part to achieve some separation, so that they can change independently.

  • JAVA bridge mode 2010-03-29

    1. From the Talking Tree Basically, everyone knows that the concept of a tree. Slightly go into. NET will understand the nature of,. NET has a object tree. Learning ASP.NET, people would be aware, Web on a control tree. Even if it is studied only the

  • php and java bridge - javabridge 2011-03-27

    2008-03-05 17:26 Since the project needs to be used php Call java, tried it two ways to bridge ( Local test ,windows) A :. Module with php php_java.dll 1. Php.ini configuration file Remove ;extension=php_java.dll Semicolon in front of [java] java.lib

  • php call to java, and generate reports jasperReports 2010-03-12

    php call to java, and generate reports jasperReports Keyword php java bridge iReport jasperReports pdf 1. First install and configure the environment, please refer to the predecessors of the article I also provide a reference address http://zhengdl12

  • Configuring php-java-bridge, PHP file calls itself JAVA 2010-08-28

    php_java.dll need to configure the php.ini, the new version of php-java-bridge no dll files First make sure your PHP and Apache server and the JDK (or JRE also) have been installed Internet Download php-java-bridge (to get the wear points or http://s

  • JavaScript and Java What would you choose? 2010-10-22

    Oracle recently sued the search giant Google, announced its Android smartphone operating systems Dalvik Java virtual machine patent infringement, it is natural to worry about a lot of developers. But most analysts pointed out that the vast majority o

  • php call to your java (rpm) 2010-12-02

    ----------------------------- Recommended method: JavaBridge.jar The beginning to install jdk this would not have

  • Java send mail via MS Exchange 2011-07-14

    The company developed systems through the customer's Exchange Server to send mail on the Internet for many programs, current the Java Bridge to Exchange to solve the problem, now code posted out. public cla

  • Use EWS Java API 1.1 send mail 2011-09-29

    Because the project needs to send mail through the Exchange mail server, and use moyosoft the Java Bridge to Exchange solution is only one month trial period, after a trial period to pay for, so the Internet to find another Exchange Web Services Solu

  • 利用RJB在Ruby on Rails中使用Java代码的教程 2014-02-14

    这篇文章主要介绍了利用RJB在Ruby on Rails中使用Java代码的教程,本文来自于IBM官方网站技术文档,需要的朋友可以参考下 开始之前 关于本教程 Ruby on Rails (Rails) 是用 Ruby 编写的一个 full-stack Web 应用程序框架,而 Ruby 是一种功能丰富的.免费的.可扩展的.可移植的.面向对象的脚本编制语言.Rails 在 Web 应用程序开发人员之间非常流行.通过它,可以快速有效地开发 Web 应用程序,并将其部署到任何 Web 容器中,例如

  • PHP与Java进行通信的实现方法 2014-10-21

    这篇文章主要介绍了php与java通信的实现方法,需要的朋友可以参考下 缘起: 最近做了一个电商平台与网银整合的小东西,程序是开源的 Ecmall的,网银的接口也很规范,给出的文档很全,唯一的小问题是,网银使用的签名和验签的lib是只有java和c的,对java还熟悉一些,所以选择了使用java作为签名和验签的接口. 方法: 网上关于php与java交互的资料其实挺多的.总体来说其实也是这么几种方法: •PHP直接通过exec或者system之类的命令调用命令行,然后以java Hello 这种

  • Experiment: Combining Merapi enhanced features Flash Player 2010-07-20

    In the previous article RIAMeeting introduced Merapi, if you do not understand, please click here . Simple to say, Merapi is based on the Socket communication Flex / Flash / AIR and Java bridge project, so that we can Java Extended Yuanxian do not ha

  • Call use the PHP package to implement Lucene full-text search 2010-11-27

    [Search] PHP calls by Lucene full-text search package to achieve -------------------------------------------------- ------------------------------ of: z33 Posted :2006 -06-24 17:43:53 [Comments] [] [Read Php forum] [Close] /

  • Webservice using Httpservice and communicate to and Flex 2010-12-23

    About httpservice configuration, flex webservice through httpservice and data transmission way, now to configure httpservice. The following sentence to the configuration can be httpservice <mx:HTTPService url="jindex.jsp" resultFormat="x

  • Third, access to the database 2011-02-18

    Third, access to the database JDBC is a java data connection (Java DataBase Connectivity) JDBC API provided by the sun, java applications and different database interfaces! JDBC Driver Manager from the sun to provide, manage different JDBC driver JDB

  • 前端工程精粹(三):本地调试与数据模拟 2014-05-03


  • ANT集成SVNANT访问SVN(Subversion) 2012-12-23

    一直想让项目的编译自动化,由于代码服务器使用的是SVN,同时脚本用的是ANT,就涉及到如何在ANT中来访问SVN,checkout/commit/update/export 等. 在网上查了很多资料,发现都没有介绍原理,只是生搬硬套,很容易搞错,却不知错在哪里.通过研究ANT,SVN,SVNANT等几方面的原始英文文档,这里准备详细说明一下. 首先,说一下我的配置: ANT ,1.8.4 SVN, 1.7.8 SVNANT:1.3.1 , 时间:2012.12.22(传说中的玛雅人预测的世界末日

  • JavaBridge install in ubuntu 2015-05-03

    最近公司有项目需要用到php调用java的接口,最终选择采用javabridge来实现中间的桥接工作. 项目的操作系统是ubuntu 11.04 server. windows的安装很简单,这里就不太讨论,只是说说ubuntu的安装. 看过了很多文档,都说需要搭设tomcat来进行jar的解析,其实大可不必这样处理. 首先通过sourceforge去下载javabridge的相关文件,地址如下:

  • Merapi project: a bridge to connect AIR with Java 2010-12-22

    Trackback URI: Adobe Flex and AIR over the past relied heavily on Java, including the Eclipse-based IDE and a Java built fully functional use of data services and products, and these products are al

  • Java设计模式之桥模式(Bridge模式)介绍 2014-08-03

    这篇文章主要介绍了Java设计模式之桥模式(Bridge模式)介绍,本文讲解了为什么使用桥模式.如何实现桥模式.Bridge模式在EJB中的应用等内容,需要的朋友可以参考下 Bridge定义:将抽象和行为划分开来,各自独立,但能动态的结合. 为什么使用桥模式 通常,当一个抽象类或接口有多个具体实现(concrete subclass),这些concrete之间关系可能有以下两种: 1.这多个具体实现之间恰好是并列的,如前面举例,打桩,有两个concrete class:方形桩和圆形桩:这两个形状

  • Great collection of java interview topics 2009-02-27

    1, object-oriented features of what has 1. Abstract: Abstract is that it has overlooked a subject has nothing to do with the current goal of those aspects in order to more fully with the current objectives of the attention-related aspects. Abstract d