25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 2 ■ Working with Classes and Dependencies<br />

Let’s start by defining your Document file (see Listing 2-1).<br />

Listing 2-1. Document.java<br />

package com.apress.isf.java.model;<br />

import java.util.Date;<br />

public class Document {<br />

private String name;<br />

private Type type;<br />

private String location;<br />

private Date created;<br />

private Date modified;<br />

}<br />

//Setters/Getters omitted<br />

Your Document class (Listing 2-1) has a one-to-one relationship with the Type class. The Type class<br />

(see Listing 2-2) defines the type of document: a PDF, a note, or a web document.<br />

Listing 2-2. Type.java<br />

package com.apress.isf.java.model;<br />

public class Type {<br />

private String name;<br />

private String desc;<br />

private String extension;<br />

}<br />

//Setters/Getters omitted<br />

Listing 2-3 shows your SearchEngine class that will use the Document class and the Type relationship. With this<br />

class, you can look for a specific type and retrieve all the relevant documents.<br />

Listing 2-3. SearchEngine.java<br />

package com.apress.isf.java.service;<br />

public interface SearchEngine {<br />

public List findByType(Type documentType);<br />

public List listAll();<br />

}<br />

Once you have your base classes, it’s time to create the implementation of the SearchEngine class interface,<br />

which for now is a simple class that will already have some of the documents listed (see Listing 2-4). You can find all of<br />

these files in /ch02/src.<br />

15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!