Logout

D—Object-oriented programming

D.1 Objects as a programming concept (6 hours)

The paradigm of object-oriented programming should be introduced through discussion and example.


OOP (Object Oriented Programming) is a programming design approach. It differs from the procedural programming approach which preceded it (with programming languages such as C and Pascal). With OOP, code is grouped as self sustainable "objects" made from specifically designed template classes. With this approach, there are gains in both reusability and reliability.


D.1.1

Outline the general nature of an object.

 

Teaching Note:

An object as an abstract entity and its components—data and actions.

Familiar examples from different domains might be people, cars, fractions, dates and music tracks.

 

Sample Question:

sdfsdfsf

JSR Notes:

General Concept of Objects

So, yes, from the teaching note, an object, in general, is indeed a particular abstract entity of a certain type/class, and it can be described in terms of "data" which describes characteristics of it, and "actions" which are things it can perform. Put another way, real-world objects, all have, at any given point in time, a state (how they are), and a set of possible behaviors (things they are capable of doing).

Identifying the state and potential behavior of real-world objects is a great way to begin thinking in terms of object-oriented programming. For example, particular instances of dogs have particular states at any given point in time (name, color, breed, hungry or not) and can exhibit, at any given point in time certain behaviors (barking, fetching, wagging tail). As another example, every bicycle also has a current state (current gear, current pedal cadence, current speed) and set of behaviors availabale to it (the ability to change the gear, the ability to change the pedal cadence, the ability to apply the brakes).

OOP Concept of Objects

Software objects are conceptually similar to real-world objects: they too consist of state and related behaviors.In OOP programming, we will be able to say that a "class" of objects is indeed defined by it's characteristics (its "data", or its "attributes") and the actions that exist to act upon those attributes.

An OOP object stores its state in fields (private variable attributes in Java) and exposes its behavior through methods (public - usually - methods in Java). Methods operate on an object's internal state and serve as the primary mechanism for object-to-object communication. Hiding internal state (via private attribues) and requiring all interaction to be performed through an object's public methods is known as data encapsulation - a fundamental principle of object-oriented programming.

 

Here are some more real-world examples.

Every "instance" of a Person has the following attributes, which will be of a particular state (size, weight etc.):

- arms
- legs
- brain
- etc

and with/to these attribures a Person can perform the following behaviours:

+ wave
+ run
+ playBasketball
+ think

 

Every "instance" of a MusicTrack has the following attributes, which will be of a particular state (number of seconds, name etc.):

- a length
- a singer/group
- a title
- digital or analogue recording

and with/to these attribures a MusicTrack can perform the following behaviours:

+ output the length of the track
+ be played
+ display the title