music
OSdata.com: programming text book 

OSdata.com

object oriented programming

summary

    This subchapter looks at object-oriented programming.

free computer programming text book project

table of contents
If you like the idea of this project,
then please donate some money.
more information on donating

Google

objects

    This subchapter looks at object-oriented programming.

classes

    Classes are the general principles and rules of how each object acts or behaves.

    A class is a blueprint or prototype from which objects are created.

—Oracle

    A class is an implementation of an abstrated data type and encapsulates both data and operations.

objects

    Objects are a specific instance or occurence of a class.

    An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life.

—Oracle

    An object is a run-time instance of a class.

distinction between objects and classes

    A class is a set of rules. A class never runs. No memory is ever allocated for classes.

    Objects are actually created in memory and run.

inheritance

    Inheritance provides a powerful and natural mechanism for organizing and structuring your software.

—Oracle

    A class inherits state and behavior from its superclass. Inheritance is a mechanism for organizing and structuring software programs.

interfaces

    An interface is a contract between a class and the outside world.

—Oracle

packages

    A package is a namespace for organizing classes and interfaces in a logical manner.

—Oracle

messages

    Objects interact and communicate with each other by passing messages.

object oriented languages

    Object oriented languages include:

    Methods, message passing, abstraction, prototypes, blocks, and modules are also important characteristics.

    Lists of some popular OO programming languages.

    The original OO languages:

    Some pure OO languages:

    Some mostly OO languages:

    Some historically procedural languages extendedd with OO features:

    Languages with some OO features:

    JavaScript is partially object oriented.

object oriented design principles

    Michael Feathers proposed SOLID, meaning Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion.

    A class should have only a single responsibility.

    Classes should be open for extension, but closed for modification.

    Encapsulate what varies.

    Favor composition over inheritance.

    Depend on abstractions. Do not depend on conrete classes.

    High level modules should not depend on low level modules. Modules should depend on abstractions.

    Abstractions should not depend on details.

    DRY (Don’t Repeat Yourself).

    A class should have only one reason to change. [Tom DeMarco 1979 book Structured Analysis and Systems Analysis]

    Program to interface, not implementations.

    Many client-specific interfaces are better than one general-purpose interface.

    Clients should not be forced to depend upon the interfaces that they don’t use. Interface Segregation Principle.

    Derived types must be completely substitutable for their base types. [Barbara Liskov in a 1987 Conference on Object Oriented Programming Systems Languages and Applications, Data abstraction and hierarchy]

    Delegate to the respective class./p>

suggestions from creator of C++

    Suggestions from Bjarne Stroustrup, creator of C++

    [1] When you program, you create a concrete representation of the ideas in your solution to some problem. Let the structure of the program reflect those ideas as directly as possible.

    [a] If you can think of “it” as a separate idea, make it a class.
    [b] If you can think of “it” as a aseparate entity, make it an object of some class.
    [c] If two classes have something signficant in common, make that a base class. Most classes in your program will have something in common; have a (nearly) universal base class, and design it most carefully.

    [2] When you are defining a class that does not implement a mathematical entity like a matrix or a complex number, or a low-level type like a linked list:

    [a] Don’t use global data.
    [b] Don’t use global (nonmember) functions.
    [c] Don’t use public data members.
    [d] Don’t use friends, except to avoid [a], [b] or [c].
    [e] Don’t access data members of another object directly.
    [f] Don’t put a “type field” in a class, use virtual functions.
    [g] Don’t use inline functions; except as a significant optimization.

other

    “It should be noted that no ethically-trained software engineer would ever consent to write a DestroyBaghdad procedure. Basic professional ethics would instead require him to write a DestroyCity procedure, to which Baghdad could be given as a parameter.”

—Nathaniel S. Borenstein

    “I invented the term Object-Oriented, and I can tell you I did not have C++ in mind.”

—Alan Kay

    “If the particulars are to have meaning, there must be universals.”

—Plato

Ada

    “43 Finally, the language provides a powerful means of parameterization of program units, called generic program units. The generic parameters can be types and subprograms (as well as objects and packages) and so allow general algorithms and data structures to be defined that are applicable to all types of a given class.” —:Ada-Europe’s Ada Reference Manual: Introduction: Language Summary See legal information

    “1 Ada is a programming language designed to support the construction of long-lived, highly reliable software systems. The language includes facilities to define packages of related types, objects, and operations. The packages may be parameterized and the types may be extended to support the construction of libraries of reusable, adaptable software components. The operations may be implemented as subprograms using conventional sequential control structures, or as entries that include synchronization of concurrent threads of control as part of their invocation. The language treats modularity in the physical sense as well, with a facility to support separate compilation.” —:Ada-Europe’s Ada Reference Manual: Section 1: General See legal information

mathematical basis

    At the basis of object oriented programming is the idea of classification.

    Classification is the grouping of things.

    Socrates and Plato proposed in the theory of forms that everything we observe in physical reality is a mere shadow of the Form. The Form is aspatial (transcends space), atemporal (transcends time), and extra-mental (beyond mere thought).

    In philosophy, a concept is the basic idea of form, as proposed by Socrates and Plato. A referent is a specific example of a concept..

    So, the dog would be the concept and Sparky or Fluffy would be the referent.

    The concept is the basic category (in object oriented programming, the class), while the referent is an individual member of the concept (in object oriented programming, the instantiation or instance.

commentary

    A look at the mathematical basis for object oriented programming will reveal an early mistake that has caused a great deal of confusion and messiness to modern implementations.

    Unfortunately, the first attempts dealt with a handful of implementation ideas that fit will with a tree-based structure of classification. This was great for those first experimental attempts, because tree structures were well understood and easy to implement.

    It didn’t take a long time for object oriented programming to be applied to concepts that were not inherently tree-like. This led to messy hacks such as multiple inheritance.

    It is probably way too late for me to suggest that we should introduce a much cleaner non-tree approach that allows for better mapping of real world concepts to computer programs and algorithms.

    Even though it is probably too late to make use of the underlying math, it it worth looking at it.


free music player coding example

    Coding example: I am making heavily documented and explained open source code for a method to play music for free — almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).

    View music player in action: www.musicinpublic.com/.

    Create your own copy from the original source code/ (presented for learning programming).


return to table of contents
free downloadable college text book

view text book
HTML file

Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.

previous page next page
previous page next page

free computer programming text book project

Building a free downloadable text book on computer programming for university, college, community college, and high school classes in computer programming.

If you like the idea of this project,
then please donate some money.

send donations to:
Milo
PO Box 1361
Tustin, California 92781

Supporting the entire project:

    If you have a business or organization that can support the entire cost of this project, please contact Pr Ntr Kmt (my church)

more information on donating

Some or all of the material on this web page appears in the
free downloadable college text book on computer programming.


Google


Made with Macintosh

    This web site handcrafted on Macintosh computers using Tom Bender’s Tex-Edit Plus and served using FreeBSD .

Viewable With Any Browser


    †UNIX used as a generic term unless specifically used as a trademark (such as in the phrase “UNIX certified”). UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Ltd.

    Names and logos of various OSs are trademarks of their respective owners.

    Copyright © 2010 Milo

    Created: November 1, 2010, 2011

    Last Updated: August 14, 2013


return to table of contents
free downloadable college text book

previous page next page
previous page next page