Java Reference
In-Depth Information
2.2 Using the IDEA editor
Now that you have some familiarity with the screen artifacts and the functionality
they represent, let's put that knowledge to practical use. You'll start by working on
your currency converter project for ACME ; then you'll apply some of IDEA 's
advanced, intelligent, Java-aware features and see how they might affect your
development process.
2.2.1
Writing the first ACME classes and interfaces
Normally, the interface for the external service (such as the currency exchange
rate service) would be defined for you already by some third-party library.
Because this is a purely fictitious example, you'll have to define one yourself and
then adhere to it. In light of that, let's assume that the interface is defined by a
single method, requestCurrentRate() , which takes two String arguments that
represent the three-letter acronym for the currency type ( USD for the U.S. dollar,
CDN for the Canadian dollar). The method returns a double that represents the
rate of exchange between the two currencies. You can create a new simple inter-
face in Java to represent this service, calling it CurrencyExchangeService and plac-
ing it in the com.acme.conversion.currency.service package using the Project
tool window (right-click the service package and then choose New | Interface ,
or press Alt+Insert on the selected package). Once it has been created, you can
edit the interface to have the code shown in listing 2.1.
Listing 2.1
The interface for requesting rates from a fictitious currency exchange
rate service
package com.acme.conversion.currency.service;
/**
* This interface defines the standard API for all currency
* exchange services. All currency exchange services, regardless
* of implementation, will adhere to this interface.
*/
public interface CurrencyExchangeService {
/**
* Requests the current exchange rate from one currency
* to another.
* @param fromCurrency the original Currency
* @param toCurrency the 'destination' or final Currency
* @return the currency exchange rate
*/
 
 
 
 
Search WWH ::




Custom Search