您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)


Extend Index

Extend Page # 3

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

 basicline.gif (169 bytes)

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