Microsoft Word – PatternExercise.docx
package pattern1;
public interface ImplementMe {
public void update();
}
package pattern1;
public class rssFeed extends SuperClass {
public rssFeed() {
super();
}
public void add(ImplementMe me) {
this.superList.add(me);
}
public void remove(ImplementMe me) {
this.superList.remove(me);
}
public void notice() {
for (ImplementMe me : this.superList) {
me.update();
}
}
}
package pattern1;
public class rssReader implements ImplementMe {
public void update() {
// TODO Auto-generated method stub
}
}
package pattern1;
import java.util.ArrayList;
public abstract class SuperClass {
protected ArrayList
public abstract void add(ImplementMe me);
public abstract void remove(ImplementMe me);
public abstract void notice();
}
package psttern2;
public class Book implements BookInterface {
private String title;
private String author;
private String publicationDate;
private int ISBN;
private int pages;
private String summary;
public Book(String title, String author, String publicationDate,
int iSBN, int pages, String summary) {
super();
this.title = title;
this.author = author;
this.publicationDate = publicationDate;
ISBN = iSBN;
this.pages = pages;
this.summary = summary;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getPublicationDate() {
return publicationDate;
}
public void setPublicationDate(String publicationDate) {
this.publicationDate = publicationDate;
}
public int getISBN() {
return ISBN;
}
public void setISBN(int iSBN) {
ISBN = iSBN;
}
public int getPages() {
return pages;
}
public void setPages(int pages) {
this.pages = pages;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
}
package psttern2;
public interface BookInterface {
public String getTitle();
public String getAuthor();
public String getPublicationDate();
public int getISBN();
public int getPages();
public String getSummary();
}
package pattern3;
public class Magazine {
private String title;
private String editor;
private String publicationDate;
private int ISBN;
private int pages;
private String summary;
public Magazine(String title, String editor, String
publicationDate,int iSBN, int pages, String summary) {
super();
this.title = title;
this.editor = editor;
this.publicationDate = publicationDate;
ISBN = iSBN;
this.pages = pages;
this.summary = summary;
}
public String getTitle() {
return title;
}
public Magazine setTitle(String title) {
return new Magazine(title,
this.editor,this.publicationDate, this.ISBN, this.pages,
this.summary);
}
public String getEditor() {
return editor;
}
public Magazine setEditor(String editor) {
return new Magazine(this.title,
editor,this.publicationDate, this.ISBN, this.pages, this.summary);
}
public String getPublicationDate() {
return publicationDate;
}
public Magazine setPublicationDate(String publicationDate) {
return new Magazine(this.title,
this.editor,publicationDate, this.ISBN, this.pages, this.summary);
}
public int getISBN() {
return ISBN;
}
public Magazine setISBN(int iSBN) {
return new Magazine(this.title,
this.editor,this.publicationDate, ISBN, this.pages, this.summary);
}
public int getPages() {
return pages;
}
public Magazine setPages(int pages) {
return new Magazine(this.title,
this.editor,this.publicationDate, this.ISBN, pages, this.summary);
}
public String getSummary() {
return summary;
}
public Magazine setSummary(String summary) {
return new Magazine(this.title,
this.editor,this.publicationDate, this.ISBN, this.pages, summary);
}
}
package pattern4;
public interface Journal {
public String getTitle();
public void setTitle(String title);
public String getEditor();
public void setEditor(String editor);
public String getPublicationDate();
public void setPublicationDate(String publicationDate);
public int getISBN();
public void setISBN(int ISBN);
public int getPages();
public void setPages(int pages);
public String getSummmary();
public void setSummary(String summmary);
}
package pattern4;
public class JournalOne implements Journal {
private String title;
private String editor;
private String publicationDate;
private int ISBN;
private int pages;
private String summary;
boolean fetched = false;
public JournalOne() {
}
protected void FetchJournal() {
// Do something to get a Journal’s Details
}
public String getTitle() {
if (!this.fetched) {
this.FetchJournal();
}
return this.title;
}
public void setTitle(String title) {
if (! this.fetched) {
this.FetchJournal();
}
this.title = title;
}
// ETC for remaining methods
public String getEditor() {
// TODO Auto-generated method stub
return null;
}
public void setEditor(String editor) {
// TODO Auto-generated method stub
}
public String getPublicationDate() {
// TODO Auto-generated method stub
return null;
}
public void setPublicationDate(String publicationDate) {
// TODO Auto-generated method stub
}
public int getISBN() {
// TODO Auto-generated method stub
return 0;
}
public void setISBN(int isbn) {
// TODO Auto-generated method stub
}
public int getPages() {
// TODO Auto-generated method stub
return 0;
}
public void setPages(int pages) {
// TODO Auto-generated method stub
}
public String getSummmary() {
// TODO Auto-generated method stub
return null;
}
public void setSummary(String summary) {
// TODO Auto-generated method stub
}
}
package pattern4;
public class JournalTwo implements Journal {
public String getTitle() {
// Get a title from Journal stored in a database.
return null;
}
public void setTitle(String title) {
// Set a title from Journal stored in a database.
}
public String getEditor() {
// Get editor from Journal stored in a database.
return null;
}
public void setEditor(String editor) {
// Set editor from Journal stored in a database.
}
// ETC for remaining getters/settings
public String getPublicationDate() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setPublicationDate(String publicationDate) {
// TODO Auto-generated method stub
}
@Override
public int getISBN() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void setISBN(int ISBN) {
// TODO Auto-generated method stub
}
@Override
public int getPages() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void setPages(int pages) {
// TODO Auto-generated method stub
}
@Override
public String getSummmary() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setSummary(String summary) {
// TODO Auto-generated method stub
}
}
I
Immutable
Pattern
(no
graphical
respresentation)