开发者

What Java feature(s) historically started as a pattern and is now a language feature? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 8 years ago.

开发者_如何转开发 Improve this question

I'll be honest. I need help with a homework question that I'm stumped with.

Describe something that historically started as a pattern and is now supported with a language feature in Java.


They're probably looking for enums.

Before Java 1.5 introduced language support for enums, standard practice was to define a set of public static final ints as enum values.
This pattern can be seen all over Swing.

Many of these constants are defined in interfaces so that classes can implement the interface and use the constants without a qualifying typename; the SwingConstants interface is a great example.


The most obvious pattern I can think of around that is iterating via Iterable<T> and Iterator<T>, which is now available as a feature via the enhanced for-each loop.


From http://en.wikipedia.org/wiki/Java_version_history: Enumerations (typesafe enum pattern)

More on this pattern in item 21 in Chapter 5 of 'Effective Java' (found here: http://java.sun.com/developer/Books/effectivejava/Chapter5.pdf)


Annotations are all about metadata that used to stored in a variety of xml files or in javadoc comments now you can use annotations to store metadata with the code.

Dependency injection is another pattern that while not part of the java language is making its way into the core jdk frameworks.


Iterators. They have a special for loop which is translated into hasNext() and next() calls.


I would suggest Generics. That was not part of Java from the beginning but was implemented from 1.5 and above.


enums.........................


Observer/Observable which is the "Observer[GOF]" pattern from the gang of four... : http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5gfso.htm

Comparator<T> which is the "Strategy[GOF]" pattern also from the gang of four : http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5ifso.htm

And many more !


Performance.


(Oops. I am sorry. Always thought C++ templates have something to do with the pattern. I was wrong)

<<<<< Ignore the following lines >>>>>

Not sure if I am right but let me take a shot.

Java Generics are roughly based on Template pattern

http://blogs.msdn.com/b/csharpfaq/archive/2004/03/12/88913.aspx (Link is on C# generics though)


There haven't been many language features added which appear in the JLS.

Perhaps you could argue that the @Override supports the pattern of overriding/implementing methods by detecting when a method was inteded to override a parent's method/implement an interface method but does not.

http://java.sun.com/docs/books/jls/third_edition/html/interfaces.html search for @Override


I noticed no one mentioned Prototype (clone) and Momento (Serializable).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜