An Overview of Object-Oriented Programming

Now that you’ve seen how easy it is to write an OpenLaszlo application, let’s take a look at OOP. Because LZX is an OOP language, OOP skills are crucial to creating effective OpenLaszlo applications.

Object-oriented programming (OOP) works by modeling applications on real-world objects. Three principles of OOP are encapsulation, inheritance, and polymorphism. LZX supports all the three.

The benefits of OOP are real. These are the reason why most modern programming languages, including LZX, are object-oriented (OO). I can even cite two well-known examples of language transformation to support OOP: The C language evolved into C++ and Visual Basic was upgraded to Visual Basic.NET.

This section explains the benefits of OOP and provides an assessment of how easy or hard it is to learn OOP.

The Benefits of OOP

The benefits of OOP include easy code maintenance, code reuse, and extendibility. These benefits are detailed below.

  1. Ease of maintenance. Modern software applications tend to be very large. Once upon a time, a “large” system comprised a few thousand lines of code. Now, even those consisting of one million lines are not considered that large. When a system gets larger, it starts giving its developers problems. Bjarne Stroustrup, the father of C++, once said something like this. A small program can be written in anything, anyhow. If you don’t quit easily, you’ll make it work, at the end. But a large program is a different story. If you don’t use techniques of “good programming,” new errors will emerge as fast as you fix the old ones. The reason for this is there is interdependency among different parts of a large program. When you change something in some part of the program, you may not realize how the change might affect other parts. OOP makes it easy to make applications modular, and modularity makes maintenance less of a headache. Modularity is inherent in OOP because a class, which is a template for objects, is a module by itself. A good design should allow a class to contain similar functionality and related data. An important and related term that is used often in OOP is coupling, which indicates the degree of interaction between two modules. Loosely coupling among parts make code reuse—another benefit of OOP—easier to achieve.

  2. Reusability. Reusability means that code that has previously been written can be reused by the code writer and others who need the same functionality provided by the original code. It is not surprising, then, that an OOP language often comes with a set of ready-to-use libraries. In the case of LZX, the language is accompanied by hundreds of built-in classes that have been carefully designed and tested. It is also easy to write and distribute your own library. Support for reusability in a programming platform is very attractive, because it shortens the time taken to develop an application.

    One of the main challenges to class reusability is creating good documentation for the class library. How fast can a programmer find a class that provides the functionality he/she is looking for? Is it faster to find such a class or write a new one from scratch? Fortunately, LZX core classes come with decent documentation and examples. Reusability does not only apply to the coding phase through the reuse of classes and other types; when designing an application in an OO system, solutions to OO design problems can also be reused. These solutions are called design patterns. To make it easier to refer to each solution, each pattern is given a name. The early catalog of reusable design pattern can be found in the classic book Design Patterns: Elements of Reusable Object-Oriented Software, by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides.

  3. Extendibility. Every application is unique. It has its own requirements and specifications. In terms of reusability, sometimes you cannot find an existing class that provides the exact functionality that your application requires. However, you will probably find one or two that provide part of the functionality. Extendibility means that you can still use those classes by extending them so that they suit your need. You still save time, because you don’t have to write code from scratch.

    In OOP, extendibility is achieved through inheritance. You can extend an existing class, add some methods or data to it, or change the behavior of the methods you don’t like. If you know the basic functionality that will be used in many cases, but you don’t want your class to provide very specific functions, you can provide a generic class that can be extended later to provide functionality specific to an application.

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

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