Design and Architecture of Complex Software Systems (DACSS)
Assignment 2: The Reflection Pattern - Track A: Using reflective
features of programming languages
SpaceInvadersSimulator
This is one of the choices for Assignment 2.
Objective: Using reflective capabilities of programming languages - Dynamic instantiation
Assignment description
Using the reflective capabilities of java (java.lang.reflection)
or .NET (System.Reflection)
implement a simple SpaceInvader simulator.
Requirements
The Universe is a program, running continuously and hosting different living
beings. Each being has a lifetime and "lives" according to its own style.
The Universe does not know what beings live in it. From time to time,
aliens (files containing unknown compiled classes) are teleported into
the universe using a special
teleport gate (a special folder where the class files are copied at
random moments of time). The universe acts as a friendly host and will
revive the freshly arrived aliens (instantiate them) and help them to
manifest themselves (discover and invoke their methods).
Your program has to:
- scan a given folder for files. If there are class files, the "aliens", use them
for run time type discovery with reflection.
- instantiate (through reflection) all the discovered classes. You can assume
that all the classes have a default noargs constructor.
You must not assume that the alien classes implement any known interface!
- For each alien class, discover its methods and then invoke its methods
on the created class instance. You may assume
that you will handle only methods that have no arguments or
arguments of types Integer and String. When you invoke such
methods, just create random integers or strings to give as arguments.
- An example of a file containing an alien class is given:
AlienOne.class
Bibliography
- Lecture notes for weeks 4 and 5 link
- The Java tutorials - The reflection API link
- MSDN - Reflection overview link