Components are Like Runtime Classes
|
|
Cedric has a bunch of thoughts on components. I need to respond because it seems like people still don't have a real handle as to what a component is. I summarized my definition of it a while back, however I did it in extremely generic terms.
See components as it's implemented in Java and copy-cat languages are runtime configurable entities. In fact they serve almost the same function as classes, however they are defined "partially" at runtime unlike classes which are defined at "completely" at compile time.
For motivation, take a look at servlets. Servlets are components, however behaviour configuration is done at compile time. What do I mean? To add new behaviour to a servlet you inherit from the servlet class. To add configuration you can define instance variables with initializers (doesn't matter if its static or not). But, variables for servlets can be used only for configuration, don't make the mistake of using them to store state information!
Servlets do the same thing as components that have properties and events, however it's done at compile time rather than at runtime. It's the same analogy as static inheritance versus dynamic inheritance. How do you do dynamic inheritance? Simple, use delegation. That's why you've got things like delegates and their anonymous inner class incarnation in Java.
When Allen Holub says that getter/setters are evil, he refers to its use outside the "design time" configuration needs of Java Beans. Think about it a moment, servlets eschew the use of instance variables outside configuration, however we've managed to survive with them for so long. Allen Holub may actually be making true insight here.
However, my feeling is that our unability to grasp the concept of components stems from our deep ingrained bias towards the concept of classes. If you threw away the concept of classes, then immediately it becomes a lot more homogenous and you'll get the picture. The difference between definition, design and configuration phases are all arbitrary in a prototype based system. That's how it should be.

