Saturday, February 1, 2014

Chapter 5 - Generics & Listeners

Reading Material:
1.     Head First – Java
Chapter 16 – Data Structures
2.     WikipediaObserver Pattern
a.     Chapter 3 – Methods Common to All Objects (items 8, 9)
b.    Chapter 5 – Generics (Item 25)

Exercise:
·         Add the following events to FileEncryptor (choose correct parameter types of each event):
o    encryptionStarted
o    encryptionEnded
o    decryptionEnded
o    decryptionStarted
Activate them in the appropriate places (the events are supposed to be expressed as methods in the interface, as you read in the Observer Design Pattern – which is the Observer and which is the Subject).
How would you know what is the time? (System class).
·         Create the class EncryptionLogger that registers to these events and writes messages like: “the encryption for file X with algorithm Y took Z miliseconds. The encrypted file is located in file F”.
o    Create EncryptionLogEventArgs class that includes the relevant information for each message.
o    For now, the log messages will go into the console.
·         Create a class called EncryptionLog4JLogger that writes to Log4J’s Logger (you must add the Log4J dependency to your pom file).
·         Implement equals and hashCode for EncryptionLogEventArgs (what is the difference between equals and ==? How can we ensure that both options behave the same?)
·         Change the Key definition In EncryptionAlgorithm, add a generic parameter that will be the key.
You will have to change all the implementations of the interface and the automatic tests. (Look again at
DoubleEncryption. You will have to create a new class that is a key and has 2 keys).

·         Explain what does “covariant” mean?

No comments:

Post a Comment