Tuesday 4 November 2008

My First 500(ish) Words - Please be kind!!

OK - Here are my first 500(ish) words for Chunk 59.

I would appreciate it if everyone could take a look and be constructively critical of it.

-------------------------------------------------------------------------------------------------------

An Introduction to Object Oriented Programming (OOP)

What is OOP?

Traditional programming languages, such as Pascal, COBOL, C and Visual Basic (amongst others) are procedural languages. In a procedural language you develop the code in a linear format, like a shopping list for example. You define your function and procedures in terms of (essentially) a list of instructions, building libraries of functions and procedures that perform specific tasks which allows you (the programmer) to modularise your code. Thus providing the facilities to create libraries of functions for reuse.

OOP uses a different paradigm and introduces a whole new plethora of terminology and we will only cover a few of these terms here. The three main terms we will become familiar with are class, method and message. However, we will also discuss properties, instances and inheritance. A few other terms will popup but will only be discussed in very basic detail.

OOP uses the concept of objects that describe “real world” things such as a person, an animal or a shape such as a square. It still employs procedures and functions but these are now called methods (more on this later). In procedural programming you have variables which allow for such things as counting, in OOP these are now termed properties (again more on this later). When a function or procedure was called you would issue a command such as foo(some argument [,maybe some more arguments]). In OOP you achieve similar goals by issuing messages to the object.

When an object is created from a class (more shortly) you can pass messages to it, the object can perform calculations and pass messages back which can be processed by other objects. A properly programmed class will know (also known as anthropomorphism) about itself. For instance, a class created to store the details of a person may have the facility to answer how tall it is; i.e. it knows its own height!

To interact with the object and call its functions and access it properties you use the objects interface. The interface defines all publicly accessible methods and properties of the class. As with procedural languages where you can create libraries of functions and procedures, you may also create libraries of classes that can be used in different programming projects.

Why would we use classes? Once a class is developed and tested it can be used in many different projects. OOP allows inheritance so if additional requirements are required the class can be extended and new functionality added with modification to the original class. What does this achieve? Less bugs and a high reusability factor!

The purpose of this short tutorial is to explain various basic concepts of classes with no reference to actual code, be it Java or otherwise.

3 comments:

  1. I think you need to check the term 'anthropomorphism' - which means "to have human qualities or feelings".
    There is 'polymorphism' (from the Greek meaning 'many forms'). Polymorphism is when an object exhibits different behaviour dependent upon the context. For example, take the '+' symbol: when used in the context of "1 + 2" will yield '3', but when used in the context of "'fred' + 'bloggs'" will yield 'fredbloggs' - so different behaviour. In other words, when '+' is sent to an object of one of the number classes it will perform an 'add', but when the '+' is sent to an object of the string class it performs concatenation, and so on.

    ReplyDelete
  2. Hi Simon, thanks for that and I will investigate my use of the term.

    However, I am sure that in the dim and very distant past that M206 defined anthropomorphism as being "attributing human like behaviour to a software object", which is the point I was trying to convey; the object created from the class "knows" about itself.

    Perhaps I was not concise enough in my description and will review it.

    Again thanks for the feedback. It is much appreciated.

    ReplyDelete
  3. Hi Bryan, Ah M206 - what a good course that was. You may be right - I'm not sure my memory works well that far back - its just not a term I come across since when doing OO stuff.
    By the way, I found your blog via the blog of Ian Macey - who is also involved in this Chunk thing. I'm not part of it - not far enough advanced in my degree yet :-(

    ReplyDelete