Overview of OOP

Overview of Object-Orientation

“After years of relative obscurity, object orientation appears to be entering the mainstream of commercial computing for both software developers and end users. A shift to object orientation is occurring simultaneously across a wide range of software components, including languages, user interfaces, databases, and operating systems. While object-oriented programming is no panacea, it has already demonstrated that it can help manage the growing complexity and increasing costs of software development”.

 

                – from Object-Oriented Software by

                               Winblad, Edwards & King

This quotation is an excellent summary of what is happening in the world of computing today. Although exciting research and development is taking place on many fronts, no single software topic currently enjoys as wide a scope or impact as object orientation. Some of the most advanced and powerful software products available today incorporate object orientation as a central concept: languages such as Smalltalk, C++, and Actor; leading edge minicomputer databases such as Ontos and Servio Logic’s Gemstone; expert system development tools such as Neuron Data’s Nexpert Object and Level 5 Object from Information Builders; and graphical user interfaces (GUIs) such as Microsoft Windows, as well as UNIX GUIs such as Open Software Foundation’s Motif, and Sun Microsystems’ Open Look.

Although object orientation applies in slightly different ways in each of the areas mentioned above, the same basic concepts are being applied in each case. Because of its broad scope, the term is often misused, especially in marketing claims; indeed, articles have been written on this subject, such as “My Cat is Object-Oriented”, by Roger King of the University of Colorado.

This abuse often arises from the fact that object orientation in user interfaces is not easy to define clearly, and it is through user interfaces that end users encounter object orientation, usually without realizing it. Some vendors assert that their products are object-oriented merely because they use screen windows – the windows are objects, the argument goes, and therefore the program is object-oriented.

This is perhaps an extreme of misrepresentation, but the situation is complicated by in-between products such as Microsoft Windows. At both the user interface and programming level, Windows is object-oriented in many ways, but in other ways falls far short of being “fully” object-oriented.

The aspect of object orientation which Class(y) addresses is that of object-oriented languages. The features required of an object-oriented language are well defined, and existing language products set something of a standard in this area. Once familiar with the principles of object-oriented languages, it becomes much easier to differentiate between true and false claims about object orientation in other areas.

One of the main driving forces for the adoption of OOP is likely to be the need to produce programs that run under graphical user interfaces such as Microsoft Windows. This means that changing from procedural to object-oriented programming may involve changing not just the language being used, but the operating environment, resulting in an extremely steep learning curve.

While GUIs promise to make life easier for the end user, they will only make it harder for the programmer, unless we are prepared to change our programming style. Writing programs with a completely object-oriented architecture simplifies development for GUIs, since the program architecture reflects the architecture of the underlying environment.

Although we cannot write Microsoft Windows applications using standard Clipper just yet, we can prepare ourselves by starting to develop object-oriented programs. This will allow us to climb the learning curve gradually, rather than suddenly being forced to learn a new programming style as well as the complexities of event driven programming in a GUI.

We’ll start our climb of the learning curve with a brief look at the history of object-oriented languages, followed by an introduction to object-oriented concepts.

Brief History of Object-Oriented Languages

The concept of an object class and inheritance, central to object-oriented languages, was first implemented in the language Simula 67, an extension of Algol 60 designed in 1967 by Ole-Johan Dahl and Kristen Nygaard from the University of Oslo and the Norwegian Computing Center (Norsk Regnesentral). Although Simula, as it is now called, is a general purpose programming language, it is not in wide usage.

A major milestone in the development of object-oriented languages was the Smalltalk research project at the Xerox Corporation’s Palo Alto Research Centre (PARC). Starting in the early 1970s, the Smalltalk project, initiated by Alan Kay, had as its goals more than just the development of a programming language; rather, a complete integrated environment was the goal, including an object-oriented language, development tools, and a graphical interface. The standard components of modern graphical user interfaces, such as windows, icons, and the mouse, were pioneered at Xerox PARC.

The Smalltalk language itself was the first ‘true’ object-oriented language in that it dealt exclusively with objects. All subsequent object-oriented languages have been based on the concepts used in Smalltalk. Smalltalk was important, not just for its language, but for the development tools available in the Smalltalk environment. These include class browsers and object inspectors. A class browser is a very powerful tool which allows program code to be edited in a much more convenient and structured way than with conventional editors. Because of the inherently well-defined structure of object-oriented programs, the class browser is capable of displaying a given program’s class hierarchy in graphical form, allowing the user to ‘point and shoot’ to select a particular method (procedure) to be edited. Many programming tasks become menu driven, such as the creation of new classes, modifying the structure of the inheritance tree, and modifying the structure of a class. These operations are more complex and tedious when performed in a traditional editing environment.

Tools such as these are an integral part of the promise of object-oriented technology. They can simplify a programmer’s life, reducing development time and costs. Although they are a rarity in the DOS world at present, as the move toward object-oriented technology grows, and as we move towards GUIs like Microsoft Windows, these tools will become more commonplace.

What is an Object?

One of the fundamental reasons that object orientation is enjoying such success as a programming paradigm is very simple: the real world is made up of objects. An invoice is an object. A stock item is an object. A balance sheet is an object. An entire company is an object. Objects can contain other objects (this is called composition); and in this way complete systems can be constructed using objects.

But what is an object from a programming point of view? Simply put, it is a collection of related data, which is associated with the procedures which can operate on that data.

By this definition, most well-structured programs could be said to contain objects. This is another contributing factor to the confusion surrounding the definition of object orientation.

It is in fact possible to write programs in an object-oriented way in many traditional procedure-oriented languages. However, without the support provided by an object orientated languages, many compromises have to be made.

An object-oriented language formalizes the relationship of the data within an object to the program code which can operate on that data, by requiring that the compiler or interpreter be informed which procedures are allowed to operate on an object’s data.

Before we can clarify our definition of an object further, we need to explore a few other concepts.

Classes, Instances and Instance Variables

In any given system, many objects will exist. Many of these objects will be very similar to each other: for example, you might have thousands of invoice objects stored on disk. Although each one is different, they all share a common set of attributes. The same operations are valid on all of them. There is a term to describe such a collection of similar objects: it is called a class.

A class can be thought of as a template, or specification, for creating an object. The class itself consists of details specifying what the structure of its objects should be. The class can also be said to ‘contain’ the program procedures which are permitted to operate on objects of that class.

For example, an Invoice class would contain procedures for printing and updating invoices. It would also contain details of the structure of an invoice object, for example that each invoice object must contain variables named date, customer, amount, etc.

To look at it another way, we can define an object as an instance of a class. A given class may have many instances of itself (objects) in existence at any one time. Each of these instances has a structure determined by the class to which it belongs, but they are distinguished from each other by the data within that structure, which is stored in instance variables. The term instance variable distinguishes a variable that belongs to an object class from the ordinary stand-alone variables that we are used to. Instance variables are contained within objects, and are not directly accessible outside of those objects, although they can be accessed by sending messages to their objects.

Messages and Methods

Earlier, an object was defined as a module containing both procedures and data. An object’s procedures are known as methods. This terminology helps to distinguish them from procedures which are not associated with an object, since there are fundamental differences. In a fully object-oriented system such as Smalltalk, there are no procedures, only methods. In a hybrid system such as C++, or Clipper with Class(y), both methods and procedures can coexist.

Methods are not called in the same way that procedures are. Rather, messages are sent to objects, which respond by executing the appropriate method. All valid operations on or using the data in an object are defined by its methods, so all operations on an object are accomplished by sending messages to the object. Because of this, it is not necessary for other objects to access, or even know about, the internals of foreign objects. Objects behave like black boxes: send them a message, and they respond by executing the appropriate method. Send the print message to an invoice object, and it will respond by printing itself. This black box approach is known generally as encapsulation, and while it is possible to achieve in procedural systems, object-oriented systems actively encourage, support and enforce it.

Inheritance – Superclasses and Subclasses

Common properties among groups of classes can often be combined to form a parent class, or superclass. For example, it might make sense for a Quotation class, an Order class, and an Invoice class to all share the same superclass, a Sales Document class. The Quotation, Order, and Invoice classes are thus subclasses of the Sales Document class. This is known as inheritance. The subclasses inherit all the properties of their superclass, and may add unique, individual properties of their own. This concept can be extended further, with subclasses of subclasses. Such class hierarchies are a common feature of object-oriented systems.

Inheritance is one of the most powerful features of object-oriented programming, since it allows reuse of existing code in new situations without modification. When a subclass is derived from a superclass, only the differences in behavior need to be programmed into the subclass. The superclass remains intact and will usually continue to be used as is in other parts of the system, while other subclasses are using it in different ways.

Polymorphism

The term polymorphism in this context refers to the fact that the same message, such as print, can result in different behaviors when sent to different objects. Sending the print message to a graph object has a different effect than it would on a balance sheet object. With a traditional procedural approach, the programmer is forced to differentiate procedure names, using names like PrnBalSheet and PrintGraph. In an object-oriented language, this differentiation is unnecessary, and in fact unwise.

Polymorphism has benefits for the programmer in that the same name can be used for conceptually similar operations in different classes, but its implications go deeper than that. It means that a message can be sent to an object whose class is not known. In a procedural system, given a variable of unknown type, a CASE statement would typically be required to test the type of the variable and pass it to the correct procedure for the desired operation. In an object-oriented system, a message is sent to the object with no testing, and the object responds accordingly.

This has important implications for inheritance, since it means that methods belonging to classes near the root of the inheritance tree do not need to know details of the subclasses which may be inherited from them. By sending messages with standardized names to the objects with which it deals, generic methods can be written which can later be used with any class which supports the required messages.

Anton van Straaten

 

 This article borrowed from manual of famous Clipper 3tdh party Library : CLASS(Y)

 http://www.the-oasis.net/ftpmaster.php3?content=ftplib.htm

Advertisements

HMG Samples

About HMG Samples

Language Related

 Arrays

Array Arithmetic

Load / Save ANY array

Conversion

DOS -> Windows Character Conversion

National Issues

National Alternate Collating Sequence

National Change Case

 Windows

Tracking Mouse

Controls

Browse

Quick Search    

Combo box

Dynamic ComboBox

Edit Box

Word wrap in EditBox

 Grid

Get Data Into Grid via IDE

Text Box

Auto fill in text box

Search in and Fill Box (SFilBox) 

Tree

Tree Menu

Two Methods for Tree

Functions

 Drives, Directories and Files

Drives and Directories

Directory List

Fill Directory List

PutFile() with default file name

Messages

HMG Message Functions

Message for multiple values

Message Extended

Where Is It ?

Improvements in Message functions

Miscellaneous

Is application running ?

Get Process ID

Simple Error Handling

Funny

Cuckoo Clock

Untouchable window

Warn Lazy User

Pegs Game

Drawing

Play Draw

Draw Border

Printing

 Text Mode

Using printer under Windows 

Obsolete ways

Send to File

Print File

GUI Mode

HMG Print

 HMG Print ( Mini Print ) for beginners in 10 easy steps

Print a plain text file by HMG Print – 1

HMG Report

HMG HPDF

HMG_HPDF — Bill

Unicode

HMG Unicode

Utilities

Color Codes

DB Validate 

Hex View

Mini Agenda

DBA : Data Base Assistant

Low-Level DBU

x-Base Modul List

Mini Search Machine (2014) 

Object-Oriented Terms

Classes :

A class defines the variables contained in an object, and the operations applied when the object receives a message. Every object is an instance of a class and responds to messages of that class. Each object, however, has its own copy of the variables specified in the class definition. New objects are created In Clipper language by a calling a special function that begins with the class name followed by the New suffix.

See Also: Instance Variables, Messages, Methods, Objects

Exported Instance Variables :

See : Instance Variables

Instance Variables :

Instance variables are the attributes or the data portion of an object as defined by the object’s class. Each object, when created, is given its own unique set of instance variables initialized to their default values. Instance variables that are accessible are called exported instance variables. Exported instance variables can be inspected and–in some cases–assigned using the send operator. The instance variables of an object persist as long as the object it belongs to.

See Also: Classes, Objects

Messages :

A message is the way an object is requested to perform some action. Messages are sent to an object and composed of the object name, the send operator, and the selector name followed by arguments enclosed in parentheses. The selector has the same name as the method it is calling. Sending a message produces a return value, much like a function call with the return value varying depending on the operation performed.

See Also: Instance Variables, Methods, Objects

Methods :

A method is the operation performed in response to a message sent to an object.

See Also: Classes, Messages, Objects

Objects :

An object is an instance of a class. Each object has one or more attributes (called instance variables) and a series of operations (methods) that execute when a message is sent to the object. The object’s instance variables can only be accessed or assigned by sending messages to the object. Objects are created by calling a special function associated with a class.

See Also: Classes, Instance Variables, Messages, Methods

Self :

An object-oriented term describing a reference to the object that received the current message. In Clipper language, this reference is often the return value of a message send.

Send Operator :

A new operator (:) In Clipper language used to send messages to user interface objects.