Question: 2 . ( 1 0 pts ) The following is a typical example about head hunter. There are two roles in this example - HeadHunter
pts The following is a typical example about head hunter. There are two roles in this example HeadHunter and JobSeeker. Job seekers subscribe to a head hunter, and head hunter notifies job seekers when there is a new job opportunity. Draw the UML diagram class diagram for this design pattern. Explain the importance of this design pattern.
public interface Subject
public void registerObserverObserver o;
public void removeObserverObserver o;
public void notifyAllObservers;
public interface Observer
public void updateSubject s;
import java.util.ArrayList;
public class HeadHunter implements Subject
define a list of users, such as Mike, Bill, etc.
private ArrayList userList;
private ArrayList jobs;
public HeadHunter
userList new ArrayList;
jobs new ArrayList;
@Override
public void registerObserverObserver o
userList.addo;
@Override
public void removeObserverObserver o
@Override
public void notifyAllObservers
forObserver o: userList
oupdatethis;
public void addJobString job
this.jobs.addjob;
notifyAllObservers;
public ArrayList getJobs
return jobs;
public String toString
return jobs.toString;
public class JobSeeker implements Observer
private String name;
public JobSeekerString name
this.name name;
@Override
public void updateSubject s
System.out.printlnthisname got notified!";
print job list
System.out.printlns;
public class Main
public static void mainString args
HeadHunter hh new HeadHunter;
hhregisterObservernew JobSeekerMike;
hhregisterObservernew JobSeekerChris;
hhregisterObservernew JobSeekerJeff;
hhaddJobGoogle Job";
hhaddJobYahoo Job";
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
