Apply the appropriate transformations described in Section 10.4.2 to the associations below. Assume that all associations are bidirectional and that they can change during the lifetime of each object. Write the source code needed to manage the associations, including class, field, and method declarations, method bodies, and visibility.
What will be an ideal response?
Figures 10-2 through 10-5 depict sample classes for this exercise. Import statements and constructors were omitted.
Since no ordering was specified on the associations, a Set was used to represent the many side. If the student selects a
List, additional checking code must be added to ensure that multiple associations to the same object are not created.
```
public class Mailbox {
private Set folders = new HashSet();
public Folder [] getFolders() {
return (Folder[])folders.toArray();
}
public void addFolder(Folder f) {
folders.add(f);
f.setMailbox(this);
}
public void removeFolder(Folder f) {
folders.remove(f);
f.setMailbox(null);
}
}
```
Figure 10-2 Class Mailbox.
```
public class Folder {
private Mailbox mailbox = null;
private Set messages = new HashSet();
public Mailbox getMailbox() {
return mailbox;
}
public void setMailbox(Mailbox newMailbox) {
if (newMailbox != mailbox) {
Mailbox oldMailbox = mailbox;
mailbox = newMailbox;
if (newMailbox != null) {
newMailbox.addFolder(this);
}
if (oldMailbox != null) {
oldMailbox.removeFolder(this);
}
}
}
public Message [] getMessages() {
return (Message[])messages.toArray();
}
public void addMessage(Message m) {
messages.add(m);
m.setFolder(this);
}
public void removeMessage(Message m) {
messages.remove(m);
m.setFolder(null);
}
}
```
Figure 10-3 Class Folder
```
public class Message {
private Folder folder = null;
private Set views = new HashSet();
public Folder getFolder() {
return folder;
}
public void setFolder(Folder newFolder) {
if (newFolder != folder) {
Folder oldFolder = folder;
folder = newFolder;
if (newFolder != null) {
newFolder.addMessage(this);
}
if (oldFolder != null) {
oldFolder.removeMessage(this);
}
}
}
public View [] getViews() {
return (View[])views.toArray();
}
public void addView(View v) {
if (!views.contains(v)) {
views.add(v);
v.addMessage(this);
}
}
public void removeView(View v) {
if (views.contains(v)) {
views.remove(v);
v.removeMessage(this);
}
}
}
```
Figure 10-4 Class Message.
```
public class View {
private Set messages = new HashSet();
public Message [] getMessages() {
return messages.toArray();
}
public void addMessage(Message m) {
if (!messages.contains(m)) {
messages.add(m);
m.addView(this);
}
}
public void removeMessage(Message m) {
if (messages.contains(m)) {
messages.remove(m);
m.removeView(this);
}
}
}
```
Figure 10-5 Class View.
You might also like to view...
Answer the following statements true (T) or false (F)
1. A class member function may be private. 2. Class data members are almost always public. 3. It is possible to have multiple private labels in a class definition. 4. The assignment operator may not be used with objects of a class. 5. All constructors for a class must be private. 6. A derived class is more specific than its parent, or base class.
A ________ is an individual who seizes supervisory control of the system and uses this control to evade auditing and access controls or to suppress audit collection. ?
A. clandestine user ? B. misfeasor C. masquerader ?? D. mole
One advantage to using a form is that you can display data from more than one table at the same time
Indicate whether the statement is true or false
The architecture of a(n) ____________________ firewall provides a DMZ.
Fill in the blank(s) with the appropriate word(s).