Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott.

13
Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott

Transcript of Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott.

Page 1: 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

Page 2: Unit 15 Java 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).

Page 3: Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott.

• 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.

Page 4: Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott.
Page 5: Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott.
Page 6: Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott.
Page 7: Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott.

• 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

Page 8: Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott.

• 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

Page 9: Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott.

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

Page 10: Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott.

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

Page 11: Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott.

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

Page 12: Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott.

In Summary and Mnemonic Devices:

• Iterator: Remember Java collections• Template: Remember Java sorting• Strategy: Remember multiple classes

implementing the same interface

Page 13: Unit 15 Java Interfaces: Using an Interface to Accomplish a Specific Goal Kirk Scott.

The End