• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Objecttive 1.5

 
Paulo Aquino
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this objective, it ws mentioned that exam takers should know how to describe and apply the "program to an interface" principle. Can anyone shed light to this principle?
 
Dave Wood
bronco
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a copy of Design Patterns handy (and if you don't, you SHOULD!), read pages 17-18 for a discussion of this topic.

In a nutshell:


Don't declare variables to be instances of particular concrete classes. Instead, commit only to an interface defined by an abstract class (Dave comment: or interface).


Note that this concept is not literally talking about Java interfaces (in the DP book, which is generally C++ oriented, they just talk about abstract classes), though they certainly apply.

There are not a lot of exam questions on this topic. You just need to understand the basic idea. For example:

HashMap hm = new HashMap(); // not programming to an interface

vs.

Map map = someFactory.createMap(); // programming to an interface

HTH,
Dave
 
Mahesh Kumaraguru
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paulo Aquino:
In this objective, it ws mentioned that exam takers should know how to describe and apply the "program to an interface" principle. Can anyone shed light to this principle?


"Program to an interface" is discussed with examples at

http://www.coderanch.com/t/178299/java-SCJA/certification/describe-apply-program-interface-principle
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic