|
|
08.21.2003 |
|
||||||||||
| Objects vs. Components | ||||||||||||
I'm quite interested in the concept of software components and how those ideas can be applied to Java code. Thoughts or ideas I have on this subject get dropped here for the benefit of humanity and my own hubris.
|
In a conversation I had today, a great perspective/definition of components and objects came up. The ultimate author of this idea was Cat Johnson (so I guess I should give credit where credit is due), but I really like it. Components are all about encapsulating a “process” where objects are about encapsulating the “data.” So while a typical object would be a “credit card,” a good component would be a “credit card processing”. OOP is all about … well, objects. The storage and management of data. But data objects are much more useful when you consider their relationships with other objects. This is why objects aren’t typically reusable. If you want to reuse an object, you need to grab all of the other objects that it has relations with. A “component” on the other hand, is all about insulating the relationships behind interfaces. This way, you can reuse the service. Granted, these “actions” are also useless without the supporting objects, and so components tend to be larger than objects as it contains the necessary objects inside. However it does mean that you have a complete package. This is probably why web services have potential to become reusable … they are services. You don’t think of a “weather web service,” you think of a “weather reporting web service.” They do a job without the client having to instantiate and coordinate a lot of supporting characters. So, if you think about breaking your application done into its “jobs” and not into its characters, you end up with components that can be independent and reusable (see my previous definition discussion). This method is not unlike your typical workplace environment. The “Org Chart” is really about responsibilities, jobs performed, and the interfaces between the objects that implement them. As long as the processes (interfaces) are in place, each worker is replaceable with a similarly skilled worker, and you get better coordination between the team members. Thought originally posted on Thursday, 21 August 2003
© 2003-2005, Howard Abrams • Except where otherwise noted, all original content is licensed under a Creative Commons License (see details). A comment to this from Howard
Wm Leler just pointed out the source of this idea, the Building Good Component-based Applications, a guide that Wm has been putting together on how to build good components and component-based apps (with lots of help from Cat): Unlike objects, good components tend to be based on function, rather than feature. Put another way, when creating components, think algorithmically rather than about the domain. Think about functions or services to be performed, like charging a credit card or formatting a date, rather than an object, like a Customer or a Color. A Customer component will be difficult to reuse, since the concept of a Customer is specific to the domain of your application. Likewise, different application domains will use colors in very different ways. Always remember that components are not the same thing as objects.Comment posted on Thursday, 21 August 2003 A comment to this from Ben Fairfax
Another interested point which Wm made in another article is the premise that: `A Component should only admit methods with primitive (or database) types’. Since, otherwise the Component will depend on an external object. This places Components in the role of being the building blocks of SOA. If this aim can be achieved (and it should be, since end-users only know database types) then WS (XML, SOAP, HTTP) can be used to allow interoperability between everything. The only nagging thought in my mind is well, what about transactions, and do we still have to use those Cookies of the CGI stateless world. Comment posted on Tuesday, 21 October 2003 |
|||||||||||
|
||||||||||||