Optional reflection topic
Optional reflection topic –
'mix-in' classes
A `mix-in' class is one that
provides a small amount of functionality. Mix-ins are intended to simplify implementation;
a mix-in class rarely models a real-world entity.
Here is an example. It may be useful to
allow objects to be able to save their states to a disk file. For example, when I start my
word processor, its appearance is very much as it was when I last used it (position on
screen, layout of buttons, etc). Clearly the objects that model the screen appearance are
able to `remember' their variables from the last use of the program. The programmer may
get this feature by defining a class called, say, CanSaveToDisk,
and making all other classes subclasses of CanSaveToDisk. This is an example
of a mix-in class; it provides a small, well-defined piece of program functionality.
Java does not readily support mix-in programming.
Why?
Can anything be done about this?
Reflect back to the 'dimond of death' and problems
of multiple inheritance — the use of `mix-in' programming presents a particular
problem in this regard. Why?
Back to top

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg
|