Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott.
-
Upload
samuel-atkinson -
Category
Documents
-
view
213 -
download
0
Transcript of Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott.
Unit 15Java Interfaces: Using an Interface to
Accomplish a Specific Goal
Kirk Scott
Barley
• From Wikipedia, the free encyclopediaJump to: navigation, search For other uses, see Barley (disambiguation).
• Barley (Hordeum vulgare L.), a member of the grass family, is a major cereal grain. Important uses include use as animal fodder, as a source of fermentable material for beer and certain distilled beverages, and as a component of various health foods. It is used in soups and stews, and in barley bread of various cultures. Barley grains are commonly made into malt in a traditional and ancient method of preparation.
• This is an introductory unit.• These are the units/chapters belonging to this
section of the course:• Unit 16, Iterator, book chapter 28• Unit 17, Template, book chapter 21• Unit 18, Strategy, book chapter 23
• What will be given next is an extremely brief overview of these topics.
• Although the patterns are different from each other, they can be viewed as having this broad characteristic in common:
• They make use of an interface to accomplish their goal
• Iterator and Template both show how to make use of characteristics of the Java API
Iterator
• Book definition:• The intent of the Iterator pattern is to provide a
way to access the elements of a collection sequentially
• Comment mode on:• Large parts of this should already be implicitly
clear if you understood for each loops• You will see that this pattern is used by the Java
API in dealing with collection classes
Template
• Book definition:• The intent of the Template pattern is to
implement an algorithm in a method, deferring the definition of some steps of the algorithm so that other classes can redefine them.
• Comment mode on:• You will see that the template pattern is used in
the Java API to support the ordering and sorting of objects in collection classes
Strategy
• Book definition:• The intent of Strategy is to encapsulate alternative
approaches, or strategies, in separate classes that each implement a common operation.
• Comment mode on:• This pattern is actually quite simple• You can have multiple classes implementing the same
interface—and thus the same method• The implementations of the methods may differ in the
classes
In Summary and Mnemonic Devices:
• Iterator: Remember Java collections• Template: Remember Java sorting• Strategy: Remember multiple classes
implementing the same interface
The End