Discussion -- Call for answers : Class and Component

Dear all,

1. Component has a clear seperation between the specification and implementation? I can't understand here.The interface define some operations,but eventually we need coding to realize it. Where is the speration?

A class also has methods and coding to realize it. But why we never say a class has a seperation between the specification and implementation?

2. Component has interface; Java has interface. Are they the same idea or different?

Call for answers.

Thanks

Kevin

[529 byte] By [kevnyanga] at [2007-9-28 15:26:50]
# 1
Stop cross posting!
tsitha at 2007-7-12 12:17:50 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

Hi, Kevin,

First of all, I need to clarify some terminologies and then try to anwser your questions.

(1) Interface only defines operations, but does not specifies how to implement those operations. In Java, abstract class and interface are interfaces. In CORBA, IDL is interface which can be implemented by differenct programming languages.

(2) Java class is both an interface and an implementation, because it not only defines operations, but also implements the operations.

(3) Component provides some specific functionalities, but is not a full-featured application. Usually, a full-featured application consists of many different components. A component can be large or small. A component can be as large as consisting of tens or hundreds of interfaces and classes, like EJB container and server. On the other hand, a component can be as small as comprising only one class; suppose you write a component to calculate foreign currancy conversion.

(4)Specification is a written document that tries to standardize the development of a large component. A specification specififies each party's responsibilities, such as application developers'responsibilities, vendor's responsibilities, administrtor's responsibilities and so on. Also, it specifies the contracts (interfaces) between each party. In doing so, a component can be made very reuseful and can be plug-in and play; changing different vendor's component without breaking application developer's owner code.

In Java world, you see a lot of specifications, such as JDBC, EJB and JMS. When SUN defines those specifications, they use Java interfaces rather other classes to specify interfaces. Here, clear seperation between interface and implementation is very important. (1) If a class is used to specify an interface, SUN must provide implementation for the class. But, the purpose of the specification to allow different vendors to provide implementation.(2) Implementation details can very complex and different vendors may implement the same component very differently. A specification only specifies interfaces but not the implementation. The implementation is up to the vendors. Any implementation is ok as long as they comply to the contracts (interfaces). For instance, one vendor may implement a specified interface using one class and another vendor may implement the same interface using three classes. If a class is used to specify an interface, you restrict vendors' implementation. Usually, in a specification, if you find a class that is used to defines an interface, it means that SUN will provide common implementation for it and vendors do not need to implement it.

In OO design and programing, clearly seperating interfaces from implementations is vital. We should program interface rather than program implementation.

Thanks.

Tommy

MuranoYina at 2007-7-12 12:17:50 > top of Java-index,Other Topics,Patterns & OO Design...