English 中文(简体)
java.io使用最多的模式是什么?
原标题:What is the most used pattern in java.io?

我最近在工作面谈中曾问过这个问题,我无法回答。 因此,java.io最常用的模式是什么? 普通java图书馆使用的其他模式是什么?

最佳回答

我猜测他们想听到Decorator patterns,可在各行各业、读者和作家中找到。

其他模式(小型选择):

我确信,在 Java SDK,人们可以找到几乎所有模式的实例:

问题回答

rel=“noreferer”>BufferedReader http://en.wikipedia.org/wiki/Decorator_pattern”rel=“noretinger”>decorator patterns。 http://java.sun.com/javase/6/docs/api/java/io/Reader.html


Other patterns


Anti-patterns

除其他人所说的话外,这些图书馆还有几个网站anti-patterns in the Java Library:

Antipattern: inheritance instead of composition

www.un.org/Depts/DGACM/index_french.htm

Java平台图书馆明显违反了这一原则。 例如, st不是病媒,例如。 不应延伸Vector。 同样,财产清单也不是一张散列表,因此,Properties不应延伸 rel=“noretinger”>Hashtable>。 这两种情况都比较可取。

Related questions


Antipattern: constant interfaces

<>Effective Java 2nd Edition, 项目19: Use cus only to Definters/em>:

Java平台图书馆有几个固定的接口,例如java.io.ObjectStreamConstants>。 这些接口应视为异常,不应加以仿效。

Related questions


Antipattern: telescoping constructor and JavaBeans patterns

excerpt online:

传统上,方案设计人使用telescoping Constructionor 模式,在这种模式中,你只向建筑商提供所需参数,而另一套是单一选择参数,第三套是具有两种选择参数的,等等。 远程构造模式行之有效,但在有多种参数时很难写客户代码,更难以书写。

当你面临许多建筑参数时,第二种选择是JavaBeans型号,其中你称之为无参数的构造制造物体,然后使用固定方法确定每个必要的参数和每个可选择的参数。 [......] 不幸的是, Java贝人的模式有其自身的严重不利之处,[......] JavaBean可能因建造而处于不连贯的国家偏袒状态[而且]排除了使一个班子变得不可改变的可能性。

Blach建议使用builder patterns

Related questions

http://en.wikipedia.org/wiki/Decorator_pattern”rel=“noretinger”>decorator patterns 通常用于java i/o。

BufferedReader br = new BufferedReader(new FileReader("filename.txt")); 

Decorator pattern, I think. To create all flavors of Readers, Writers, input and output streams. See this, for example.

用于java.io一揽子计划的模式。

  1. Decorator_pattern

    实例:

    http://docs.oracle.com/javase/8/docs/api/java/io/FilterInputStream.html” rel=“nofollow noretinger”>java.io.FilterInputStream及其具体子类:BufferedInputStream, rapedInputStream

  2. 。 工厂_method_pattern 模式:

    实例:

    http://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html

     InputStream input = new FileInputStream("some_file.txt");
    

    下面的班级能够统一来自以下单位的投入:报警、档案、网络连接、长期储存、管道、铺设等:

     class java.io.InputStream 
           class java.io.ByteArrayInputStream 
           class java.io.FileInputStream 
           class java.io.FilterInputStream 
           class java.io.ObjectInputStream
           class java.io.PipedInputStream 
           class java.io.SequenceInputStream 
           class java.io.StringBufferInputStream
    

    实例:

    java.io.InputStreamReader 逐行转化为品行,而java.io.OutputStreamWriter则将品格流转化为星体。

  3. Template_method_pattern

    All non-abstract methods of java.io. InputStream, java.io.OutputStream, java.io.Reader and java.io.Writer.

在java的所有其它模式中,都提到这一职位:

Java核心图书馆GoF设计模式的实例





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签