Programming I (CM10134 - CM50147): Lab 9
Carry out the following exercises on Further Abstraction Techniques and Design Patterns.
You will need to show all your code for the following exercises.
Further Abstraction Techniques
- Make your Shape class in the shapes hierarchy abstract. Make any other changes to your code necessary to ensure it still compiles and runs as expected.
- Change your Shape class in the shapes hierarchy to an Interface. Make any other changes to your code necessary to ensure it still compiles and runs as expected.
- Create a university hierarchy that represents its members. The driver program should create three databases (using three different types of collection): one to store all its members, one to store staff members (admin, lecturers, professors, tutors which are taken from the PG popultation) and one to store student (UG and PG) members. Create your chosen number of members. The details of these members, such as their name and id, their pay, their subject, their location, and their contact details should be stored at the appropriate level in the hierarchy and printed out using polymorphism in the driver.
- In software engineering, solutions to common design problems are often called design patterns. One of them is called Singleton and it describes how one can make sure that a certain class can have only one instance during a program's life-cycle. How would you implement such a Singleton class in Java? How would you check that you can indeed have only one instance?