Working with Existing Objects

OOP encourages reuse. If you develop an object for use with one Java programming project, it should be possible to incorporate that object into another project without modification.


Note

The author of this book, like many in his profession, is self-employed and works out of his home. Please keep this in mind when evaluating his advice on how to conduct yourself in the workplace.


If a Java class is well designed, it’s possible to make that class available for use in other programs. The more objects available for use in your programs, the less work you have to do when creating your own software. If there’s an excellent spell-checking object that suits your needs, you can use it instead of writing your own. Ideally, you can even give your boss a false impression about how long it took to add spell-checking functionality to your project, and use this extra time to make personal long-distance calls from the office.

When Java was first introduced, the system of sharing objects was largely an informal one. Programmers developed their objects to be as independent as possible and protected them against misuse through the use of private variables and public methods to read and write those variables.

Sharing objects becomes more powerful when there’s a standard approach to developing reusable objects.

The benefits of a standard include the following:

• There’s less need to document how an object works because anyone who knows the standard already knows a lot about how it functions.

• You can design development tools that follow the standard, making it possible to work more easily with these objects.

• Two objects that follow the standard are able to interact with each other without special programming to make them compatible.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.118.180