Object Oriented Design, as a computer programming paradigm

One of the reasons why ontologies are so important to the development of semantic web, is because of object oriented design and programming. This type of programming paradigm was revolutionized with C++ in the early 1990.

From Wikipedia’s entry on Object Oriented Programming.

In computer science, object-oriented programming, OOP for short, is a computer programming paradigm.

The idea behind object-oriented programming is that a computer program may be seen as comprising a collection of individual units, or objects, that act on each other, as opposed to a traditional view in which a program may be seen as a collection of functions, or simply as a list of instructions to the computer. Each object is capable of receiving messages, processing data, and sending messages to other objects. Each object can be viewed as an independent little machine or actor with a distinct role or responsibility. Procedural to OOP may help understanding the concept using code.

Object-oriented programming is claimed to promote greater flexibility and maintainability in programming, and is widely popular in large-scale software engineering. Furthermore, proponents of OOP claim that OOP is easier to learn for those new to computer programming than previous approaches, and that the OOP approach is often simpler to develop and to maintain, lending itself to more direct analysis, coding, and understanding of complex situations and procedures than other programming methods. Critics dispute this, at least for some domains (industries).

Fundamental concepts

Object-oriented programming (OOP) emphasizes the following concepts:

  • Class — the unit of definition of data and behavior (functionality) for some kind-of-thing. For example, the ‘class of Dogs’ might be a set which includes the various breeds of dogs. A class is the basis of modularity and structure in an object-oriented computer program. A class should typically be recognizable to a non-programmer familiar with the problem domain, and the code for a class should be (relatively) self-contained and independent (as should the code for any good non-OOP function). With such modularity, the structure of a program will correspond to the aspects of the problem that the program is intended to solve. This simplifies the mapping to and from the problem and program.
  • Object — an instance of a class, an object (for example, “Lassie” the Dog) is the run-time manifestation (instantiation) of a particular exemplar of a class. (For the class of dogs which contains breed types, an acceptable exemplar would only be the subclass ‘collie’; “Lassie” would then be an object in that subclass.) Each object has its own data, though the code within a class (or a subclass or an object) may be shared for economy.
  • Method (also known as message) — how code can use an object of some class. A method is a form of subroutine operating on a single object. Methods may be divided into queries returning the current state and commands changing it: a Dog could have a query Age to say how old it is, and command chase (Rabbit target) to start it chasing a rabbit. A method may also do both, but some authorities (e.g. Bertrand Meyer) recommend they be kept separate. Sometimes access to the data of an object is restricted to the methods of its class.
    • A member of a class or object is a method or a data item describing the state of an object. In some languages the general term is feature.
  • Inheritance — a mechanism for creating subclasses, inheritance provides a way to define a (sub)class as a specialization or subtype or extension of a more general class: Dog is a subclass of Canidae, and Collie is a subclass of the (sub)class Dog. A subclass inherits all the members of its superclass(es), but it can extend their behaviour and add new members. Inheritance is the “is-a” relationship: a Dog is a Canidae. This is in contrast to composition, the “has-a” relationship: a Dog has a mother (another Dog) and has a father, etc.
    • Multiple inheritance – a Dog is both a Pet and a Canidae – is not always supported, as it can be hard both to implement and to use well.
  • Encapsulation — ensuring that code outside a class sees only functional details of that class, but not implementation details. The latter are liable to change, and could allow a user to put an object in an inappropriate state. Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface — those members accessible to that class. For example, an interface can ensure that puppies can only be added to an object of the class Dog by code in that class. Members are often specified as public, protected and private, determining whether they are available to all classes, sub-classes or only the defining class. Some languages go further: Java uses the protected keyword to restrict access also to classes in the same package, C# and VB.NET reserve some members to classes in the same assembly using keywords internal (C#) or Friend (VB.NET), and Eiffel allows one to specify which classes may access any member.
  • Abstraction — the ability of a program to ignore the details of an object’s (sub)class and work at a more generic level when appropriate; For example, “Lassie” the Dog may be treated as a Dog much of the time, but when appropriate she is abstracted to the level of Canidae (superclass of Dog) or Carnivora (superclass of Canidae), and so on.
  • Polymorphism — polymorphism is behavior that varies depending on the class in which the behavior is invoked, that is, two or more classes can react differently to the same message. For example, if Dog is commanded to speak this may elicit a Bark; if Pig is commanded to speak this may elicit an Oink.

An object-based language is a language that has most of the properties of an object-oriented language, but may lack some. For example Visual Basic lacks inheritance, while a Prototype-based programming language relies on prototypes instead of classes to create objects.

Matching Real World

According to some OOP proponents, translation from real-world phenomena/objects (and vice versa) is eased because of a direct mapping from the real-world to the object-oriented program (generally a many-to-one). OOP was even invented for the purpose of physical modelling in the Simula-67 programming language. However, not all proponents agree that real-world mapping is facilitated by OOP, or is even a worthy goal (Bertrand Meyer, OOSC2, pg. 230).

OOP as a new paradigm, point of view, and marketing term

OOP is subject to much contention as to its precise definition and its principal ideas.

In the most general terms, OOP is the practice of writing program text that is decomposed into modules that encapsulate the representation of one data type per module, instead of into collections of functions that call each other, or clauses that trigger each other. OOP concepts and practices have been brought together, with associated terminology, to create a new programming framework. Together, the ideas behind OOP are said to be so powerful that they create a paradigm shift in programming. (Other programming paradigms, such as functional and procedural programming, focus primarily on actions — or, in logical programming, on assertions — that trigger execution of program code.)

OOP arose independently out of research into simulation system oriented languages, with SIMULA 67, and out of research into highly secure system architectures, with capability-based OS and CPU architectures.

Some experts say that the original definition of object-orientation came from the object in grammar. The requirements for software are always subject-oriented. However, since the requirements for the subject are often complicated, subject-oriented programs end up tending to be complicated and monolithic. Therefore, as an alternative, some researchers started thinking in an object-oriented way. This represented a paradigm shift from the usual or previous subject-oriented mode of thinking.

According to object-oriented principles, the verb in a program statement is always attached to the object, and the logic associated with a requirement is likewise handled in the object. The following are some examples of the ways by which a subject-oriented requirement is translated into object-oriented thinking:

  • Subject-oriented: The Sales Application saves the Transaction
  • Object-oriented: The Transaction saves itself upon receiving a message from the Sales Application
  • Subject-oriented: The Sales Application prints the Receipt
  • Object-oriented: The Receipt prints itself upon receiving a message from the Sales Application

One distinguishing feature of OOP is the handling of subtypes of data types.

Objects’ data are generally required to satisfy programmer-defined constraints (i.e., class invariants). A datatype restricted by such a constraint constitutes a subtype of the same datatype without the constraint. These constraints are then both relied upon and preserved by the actions (methods) that are defined for the data.

Data constraints may be either explicitly declared or implicitly assumed by the programmer. In either case, object-oriented languages provide mechanisms for ensuring that such assumptions or constraints remain local to one part of the program. Constraints on and assumptions about data are usually included in the documentation of object-oriented programs.

OOP itself has been used to market many products and services, and the actual definitions and benefits attributed to OOP have often been colored by commercial marketing goals. Similarly, many programming languages reflect a specific view or philosophy of OOP that is narrower and, in certain respects, less general than that embodied in the more general or standard definition.

As noted above, at the end of the previous section, widely-used terminology distinguishes object-oriented programming from object-based programming. The former is held to include inheritance (described below), while the latter does not.

The exact definitions of some of these terms show some variation, depending on point of view. In particular, languages with static typing often reflect and embody slightly different views of OO from those reflected by and embodied in languages with dynamic typing, due to a focus on the compile-time rather than the run-time properties of programs.

Note: Abstraction is important, but not unique, to OOP. Other programming paradigms employ it as well.

Reusability is the benefit most often claimed for OOP. However, that claim is unlikely to be true, as reuse of software is as old as the invention of the subroutine, reputedly prior to 1950. In fact, reuse is frequently disputed as being a primary, or even a large, benefit. The ease of translation to and from the target environment, the (improved) ability to maintain a program once written, the ability to do localized debugging, and the (improved) ability to do much larger parallel development efforts, are all cited as more significant reasons to use an OOP language.

OOP is often called a paradigm rather than a style or type of programming, to emphasize the point that OOP can change the way software is developed by actually changing the way in which programmers and software engineers think about software. As a paradigm, OOP is about overall system design as much as it is about programming. A system is designed by defining the objects that will exist and interact within the system. Due to encapsulation, the code that actually does the work is irrelevant to an object, and to the people using the object. The challenge in OOP, therefore, is of designing a sane object system.

There are distinct parallels between the object-oriented paradigm and systems theory. OOP focuses on objects as units in a system, whereas systems theory focuses on the system itself. In between, one may find software design patterns or other techniques that use classes and objects as building blocks for larger components. Such components can be seen as an intermediate step from the object-oriented paradigm towards the more “real-life oriented” models of systems theory.

Actor model

OOP is a decomposition paradigm for program code, not a model for computation.

OOP is often confused with the Actor model of computation. In response to a message that it receives, an Actor can make local decisions, create more Actors, send more messages, and determine how to respond to the next message received.

Almost all OOP languages and systems, including all the major ones, such as SIMULA, Smalltalk, C++, Java, Ruby, Python, Delphi, VB .NET, and C#, have message passing programming capabilities.

See Actor model implementations for a discussion on implementations of the Actor model.

In OOP the emphasis is not on how computation is organized, but on how program text is decomposed into modules, because it is this decomposition that matters as to the program text’s comprehensibility and maintainability.

OOP is based on the assumption that the program text’s comprehensibility and maintainability are improved by decomposing the text into modules, and that the best way to decompose it into modules is to minimize dependencies among modules and maximize the cohesion of functions inside each module, and that this is best achieved by encapsulating the representation of a data type in each module.

There are several distinct styles of object-oriented programming. The distinctions between different styles occur because different programming languages emphasize different aspects of object-oriented facilities and combine with other constructs in different ways.

OOP with procedural languages

In procedural languages, OOP often appears as a form where data types are extended to behave like a type of an object in OOP, very similar to an abstract data type with an extension such as inheritance. Each method is actually a subprogram which is syntactically bound to a class.

Static typing with the object-oriented paradigm

Many object-oriented programming languages, such as C++ and Java, have a static type system that can be used to check and enforce constraints of object-oriented design to some extent at compile-time, i.e. statically. Object-oriented facilities combine with static typing in various ways. Classes are types of objects. Many object-oriented languages provide mechanisms for statically checking the type of method parameters, types of private and public data members, types of object references and check the correctness of inheritance and subtyping relationships. Static type checking can also check API compatibility, enforce data constraints on the users of libraries created with object-oriented methods and reduce the number of type checks performed at run-time for various forms of method dispatch.

Some object-oriented languages, such as Eiffel, supplement the type system with assertions specifying and documenting invariants of classes and the contracts of methods, though current Eiffel compilers only check these at run-time, i.e. dynamically.

See Class-based OOP.

Prototype-based model

Other than using classes, prototyping is another, less popular, means of achieving object-oriented behavior sharing. After an object is defined, another similar object will be defined by referring to the original one as a template, then listing the new object’s differences from the original. Perhaps the most popular prototype-based language is JavaScript, which is an implementation of ECMAScript. In prototyping systems, objects themselves are the templates, while classification systems use classes as templates for objects.

The classification approach is so predominant in OOP that many people would define objects as encapsulations that share data by classification and inheritance. However, the more generic term “behavior sharing” acknowledges alternate techniques such as prototyping.

See Prototype-based programming.

Object-based model

Object-based programming is centered around the creation of objects and their interactions, but may not have some of the key features of the class-based object-oriented paradigm such as inheritance. Such object-based systems are usually not regarded as object-oriented, because inheritance (viewing delegation as a form of inheritance) is typically identified as the core feature of OOP.

[edit]

Multimethod model

In this model, the “receiver” argument to a message is not given special status in message dispatch. Instead, the runtime values of all arguments to message are consulted to determine which method should be executed at runtime. This is related to double or multimethod dispatch.
Note that some feel that set theory or predicate logic is better suited to tackle this kind of complexity.

Possible programming mistakes

There are several common mistakes which programmers can make in object oriented programming. For example, checking the type of an object rather than its membership is a common pitfall, or antipattern, that counteracts the benefits of inheritance and polymorphism.

Critique

OOP and Code Maintenance : OOP and OOP languages by design support code centrality (e.g. through inheritance) which according to some critics increases code maintenance cost (especially for medium to large code based applications) as one bad change at higher level of hierarchy can have manifold impact through out the system. Given employee turnover ratio in IT industry is towards higher end and the new replacement will not be as code aware as older one this aspect assumes more importance. Its a very common observation among developers that those maintaining base level classes tend to avoid code changes to fix a bug (esp near milestone dates) and tend to ask developers maintaining leaf level classes to override the function at their class level to fix the same. Though through procedural language also one achieves code centrality through methods which are private in nature (i.e. the ones which are not directly accessed externally) but its a bit easier to avoid there.

According to some critics of OOP, hierarchical taxonomies and lists of mutually-exclusive options often do not match the real world and real-world changes, and therefore should be avoided. Many OOP proponents also suggest avoiding hierarchies, and instead using OO techniques such as “composition“. Critics of composition consider it too similar to the network data structures that relational was meant to replace. (More on this below.)

A simple way of avoiding over-specification of hierarchies when modeling the real world is to consider only the most specific types of objects possible, and to model relationships only between those. But deviations from hierarchies tend to complicate the use of single inheritance and “sub-type” based polymorphism.

Some critics allege that the relational model is a superior categorization and large-scale structuring tool due to its mathematical foundations in predicate calculus, relational calculus, and set theory. OOP is not based on a consensus mathematical model.

Some critics feel that OOP reverts back to the navigational database arrangements of the 1960s, which have since been replaced by relational techniques. It is not clear that this is a fault of OOP, since relational database modeling is possibly based on different fundamental premises from those on which object-oriented modeling is based. In any case, relational database tables can map to associations in object-oriented models, and the differences seem to be due to differences in focus, according to defenders.

There is a history of misinterpretation of the relationship between object-oriented and relational modeling, which may muddy this issue. Also, there are differences in opinion about the roles and definitions of each.

For example, some critics of OOP believe that it leads to unnecessary copying of noun relationship information from a database, even though the “once and only once” (i.e., no duplication) mantra would indicate that such is bad practice.

In contrast, others maintain that even though some existing OOP-to-relational database products mistakenly use a duplicative approach — confusing an object’s data with relationship data — OOP principles do not intrinsically require this duplication of data. These people argue that strict distinctions should be made between data associated with modelled objects, data associated with roles, and data associated with associations. On this view, objects’ data should not be (directly) stored in databases, because databases are not a suitable storage mechanism for objects, because every object already has some other mechanism for storing its private information, and because, as already noted, storage in a database would require unnecessary duplication between an object’s image in its own storage and in the database.

The conflict or discrepancy, or “impedance mismatch“, between OOP and the relational approach to databases is caused by differences of scale and focus between operations performed by objects and those performed by databases. Database transactions — the smallest unit of work performed by database management systems (DBMSes) — are much larger than any operations performed by OOP objects. On this view, databases are good for storing relationships between objects, and the references to objects that are associated with the roles that those relationships are built on, but objects’ data should only be stored in databases after collecting and summarising data from groups of objects. Objects’ private representation details have no place in databases.

Others argue that if objects are only meant to be small and local, then there is little need for the complexity and performance overhead of OOP. Is the “big model” of domain nouns to be in the database or in classes? Duplication factoring would dictate that it be in only one or the other.

On the other hand, there is no true performance or complexity overhead caused by OOP, and the “big noun-based domain model” is not really big from whole system perspective, since there are usually many domains in large systems. Each domain will be separately modelled, and (large-scale) architectural considerations will determine which information is stored in database. The issue which information is stored to database is completely orthogonal to the domain model identified in analysis phase. Each application (each of which use the terminology of one or more domains) will transfer information from local objects to database, when/if necessary. However, architecture and performance considerations (such as whether some classes contain information that will ultimately be stored in a database) are explicitly ignored when building the analysis model, because analysis model is built first, and is the basis to subsequent design effort. Classes built from the analysis model have nothing to do with databases.

Needless to say, the “proper” relationship between OOP and databases is a complex and contentious topic which currently has no consensus solution.

While it is claimed that OOP is better for “large applications”, others feel that large applications should instead be reduced to many small applications, such as event-driven procedures that “feed” off a database and declarative programming-based user interface frameworks.

The bottom line of the conflict seems to be that OOP is mostly a behaviorist view of software design which conflicts with the data-centric, declarative view. In the first, the “interfaces” are primarily behaviors, and data is grouped into objects. In the second, the interfaces are primarily data (declarations), and behaviours are grouped into functions, such as “tasks”, or “events”. The tradeoffs of each approach are complex; choosing among them often requires one to delve deep into theories of human psychology. Sometimes both approaches are used, such that OOP is used to build platform facilities, and a functional or declarative method is used to build applications for the platform.

Some feel that past criticisms leveled against procedural techniques are based upon poor languages, poor coding practices, or lack of knowledge about how to properly use databases instead of code to manage state and “noun models”.

It is recognized that OOP does not necessarily mean lack of complexity. Metaclass programming for example is a demanding skill, and OOP programs can have a complex web of shared or distinct responsibilities, attributes and methods. It can be challenging to distribute responsibility over objects, or classes—one of many popular implementation schemes.

Formal definition

There have been several attempts at formalizing the concepts used in object-oriented programming. The following concepts and constructs have been used as interpretations of OOP concepts:

Attempts to find a consensus definition or theory behind objects have not proven very successful, and often diverge widely. For example, some definitions focus on mental activities, and some on mere program structuring. One of the simpler definitions is that OOP is the act of using “map” data structures or arrays that can contain functions and pointers to other maps, all with some syntactic and scoping sugar on top. Inheritance can be performed by cloning the maps (sometimes called “prototyping”).

[edit]

OOP in scripting

In recent years, object-based programming has become especially popular in scripting programming languages, with abstraction, encapsulation, reusability, and ease of use being the most commonly cited reasons, (the value of inheritance in these languages is often questioned). Smalltalk is probably the first language that fits into this category. Python and Ruby are relatively recent languages that were built from the ground up with OOP in mind, while the popular Perl and PHP scripting languages have been slowly adding new object oriented features since versions 5 and 4, respectively. The ability of objects to represent “real world” entities is one reason for the popularity of JavaScript and ECMAScript, which is argued to be well suited to representing the Document Object Model of HTML and XML documents on the Internet.

History

The concept of objects and instances in computing had its first major breakthrough with the PDP-1 system at MIT which was probably the earliest example of capability based architecture. Another early example was Sketchpad made by Ivan Sutherland in 1963; however, this was an application and not a programming paradigm.

Objects as programming entities were introduced in Simula 67, a programming language designed for making simulations, created by Ole-Johan Dahl and Kristen Nygaard of the Norwegian Computing Centre in Oslo. (Reportedly, the story is that they were working on ship simulations, and were confounded by the combinatorial explosion of how the different attributes from different ships could affect one another. The idea occurred to group the different types of ships into different classes of objects, each class of objects being responsible for defining its own data and behavior.) Such an approach was a simple extrapolation of concepts earlier used in analog programming. On analog computers, such direct mapping from real-world phenomena/objects to analog phenomena/objects (and conversely), was (and is) called ‘simulation.’ Simula not only introduced the notion of classes, but also of instances of classes, which is probably the first explicit use of those notions.

The Smalltalk language, which was developed at Xerox PARC, introduced the term Object-oriented programming to represent the pervasive use of objects and messages as the basis for computation. Smalltalk creators were influenced by the ideas introduced in Simula 67, but Smalltalk was designed to be a fully dynamic system in which objects could be created, modified, and ‘consumed’ “on the fly” rather than having a system based on static objects. It also introduced the notion of ‘inheritance.’ (Thus, Smalltalk was clearly a major move beyond the analog programming models, which made no use of “instances of classes,” or even Simula, which made no use of the “inheritance property.”)

The ideas in Simula 67 were also used in many other languages, from derivatives of Lisp to Pascal.

Object-oriented programming developed as the dominant programming methodology during the mid-1980s, largely due to the influence of C++, an extension of the C programming language. Its dominance was further cemented by the rising popularity of Graphical user interfaces, for which object-oriented programming is allegedly well-suited. An example of a closely related dynamic GUI library and OOP language can be found in the Cocoa frameworks on Mac OS X, written in Objective C, an object-oriented, dynamic messaging extension to C based on Smalltalk. OOP toolkits also enhanced the popularity of “event-driven programming” (although this concept is not limited to OOP). Some feel that association with GUI’s (real or perceived) was what propelled OOP into the programming mainstream.

At ETH Zürich, Niklaus Wirth and his colleagues had also been investigating such topics as data abstraction and modular programming. Modula-2 included both, and their succeeding design, Oberon included a distinctive approach to object orientation, classes, and such. The approach is unlike Smalltalk, and very unlike C++.

Object-oriented features have been added to many existing languages during that time, including Ada, BASIC, Lisp, Fortran, Pascal, and others. Adding these features to languages that were not initially designed for them often led to problems with compatibility and maintainability of code. “Pure” object-oriented languages, on the other hand, lacked features that many programmers had come to depend upon. To bridge this gap, many attempts have been made to create new languages based on object-oriented methods but allowing some procedural features in “safe” ways. Bertrand Meyer’s Eiffel was an early and moderately successful language with those goals.

In the past decade Java has emerged in wide use partially because of its similarity to C and to C++, but perhaps more importantly because of its implementation using a virtual machine that is intended to run code unchanged on many different platforms. This last feature has made it very attractive to larger development shops with heterogeneous environments. Microsoft’s .NET initiative has a similar objective and includes/supports several new languages, or variants of older ones.

More recently, a number of languages have emerged that are primarily object-oriented yet compatible with procedural methodology, such as Python and Ruby. Besides Java, probably the most commercially important recent object-oriented languages are Visual Basic .NET and C# designed for Microsoft’s .NET platform.

Just as procedural programming led to refinements of techniques such as structured programming, modern object-oriented software design methods include refinements such as the use of design patterns, design by contract, and modeling languages (such as UML).

Advertisements

0 Responses to “Object Oriented Design, as a computer programming paradigm”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: