• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Objecttive 1.5

 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
bronco
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

https://coderanch.com/t/178299/java-SCJA/certification/describe-apply-program-interface-principle
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic