Object Oriented Programming (OOP)

Post Reply
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5214
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#1

Below is a summary of the Java programming class that took place on 26th April 2017 via LiveChat: LiveChats.

The class was a more general introduction to Object Oriented Programming rather than being specific to Java programming language.

Object Oriented Programming (OOP)
  • OOP is one of many techniques used for modeling/programming complex systems by describing a collection of interacting objects via their data and behaviors.
  • An object oriented program is based on classes and usually has a collection of interacting objects, as opposed to the conventional/top down model, in which a program consists of functions and routines. In OOP, each object can receive messages, process data, and send messages to other objects.
  • An object is a particular component of the program that can perform certain behaviors and can interact with other elements of the program.
  • Thus, an object is simply a collection of data with its associated behaviors.
  • Behaviors are actions that can occur on an object or that can be performed on an object.
  • The behaviors/actions that can be performed on a specific class of objects are called methods.
  • At the programming level, methods are like functions in structured programming
  • Methods magically have access to all the data associated with that specific object.
  • Like functions, methods can also accept parameters, and return values.
  • Parameters to a method are a list of objects that need to be passed into the method that is being called/invoked.
  • Invoking/calling a method, at the programming level, is the process of telling the method to execute itself by passing into it the required parameters as arguments.
Classes
  • Classes describe objects. They are like blueprints for creating objects.
  • A class defines a data type, which contains variables, attributes and methods.
  • Data typically represents/describes the individual characteristics of a certain object.
  • Attributes are simply referred to as properties.
  • The set of values of the attributes/properties of a particular object is called its state.
  • There can be instances and objects of classes.
  • An instance is an object of a class created at run-time.
  • Thus, objects are instances of classes and they can be associated with each other.
  • An object instance is a specific object with its own set of data and behaviors.
For example, let's consider three oranges (objects) on the table:
  • Each orange could have a different weight, the Orange class could then have a weight attribute/property.
  • All instances (see what is an instance above) of the orange class have a weight attribute, but each orange might have a different weight value.
  • So, attributes don't have to be unique; any two oranges may weigh the same.
  • Which means some of these attributes/properties may also belong to multiple classes.
For the objects to interact, they need an interface. The interface is the collection of attributes and methods that other objects can use to interact with that object.

Before you perform object oriented programming there are a number of steps to go through, especially, if the program is complex:

Object-oriented Analysis (OOA)

OOA is the process of looking at a problem, system, or task that somebody wants to turn into an application and identifying the objects and interactions between those objects.

Object-oriented Design (OOD)

OOD is the process of converting such requirements as analysed above into an implementation specification.

-The designer must name the objects, define the behaviors, and formally specify which specific behaviors/actions objects can activate on other objects.

- OOA and OOD is all about figuring out what those objects are and how they should interact.

Object-oriented Programming (OOP)

OOP is the process of converting the perfectly defined design (OOD) into a working program that does exactly as was requested.

Summing up: :eye: :writing_hand:
  • Adding models (mechanisms) and methods to individual objects allows us to create a system of interacting objects.
  • Each object in the system is a member of a certain class (eg., oranges belonging to one more classes).
  • These classes specify what types of data the object can hold and what methods can be invoked/called on it.
  • The data in each object can be in a different state from other objects of the same class, and each object may react to method calls differently because of the differences in state.
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5214
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#2

Important terms and definitions

Taught on LiveChat: LiveChats, 28th April 2017

Interface

- The interface is the collection of attributes and methods that other objects can use to interact with that object (there are however classes which are called interfaces).
- Assignment: Find out what is an interface. There are private and public interfaces. Important if you want to be a developer.

Encapsulation and Information Hiding
  • Encapsulation is, literally, creating a capsule, so think of creating a time capsule
  • By Time capsule we simply mean a container storing a selection of objects chosen as being typical of the present time, buried for discovery in the future
  • If you put a bunch of information into a time capsule, lock and bury it, it is both encapsulated and the information is hidden
  • On the other hand, if the time capsule has not been buried and is unlocked or made of transparent plastic container, the items inside it are still encapsulated, but there is no information hiding
  • Consider tablets in the plastic membrane that is transparent – they are ENCAPSULATED but not hidden, you can see the tablets but it is not easy to get into their composition details
  • In programming, the process of hiding the implementation, or functional details, of an object is suitably called information hiding, It is also sometimes referred to as encapsulation, but encapsulated data is not necessarily hidden (we have seen above)
Abstraction
  • One of the greatest gifts of modeling is the ability to ignore details that are irrelevant
  • Simply put, abstraction as dealing with the level of detail that is most appropriate to a given task
  • For example, a driver of a car needs to interact with steering, gas pedal, and brakes. The workings of the motor, drive train, and brake subsystem don't matter to him, so he/she does not concentrate on them as he/she drives
  • We can however define abstraction as the process of encapsulating information at different levels
  • synonymously, abstraction is the process of encapsulating information with separate public and private interfaces. The private interfaces can be subject to (may involve) information hiding
  • Abstracting emphasizes modeling exactly what needs to be modeled and nothing more
- Generally speaking, encapsulation/abstraction (data hiding, achieved through encapsulation) is the mechanism for restricting the access to some of an object's components

Inheritance
  • Just like a child can inherit features/traits/behaviors from his/her parents, in object-oriented programming (OOP), one class can inherit attributes and methods from another class
  • Inheritance is used to create new classes by using existing classes
  • New classes can both be created by extending and by restricting the existing classes
  • Classes can inherit other classes. A class can inherit attributes and behaviour (methods) from other classes, called super-classes. A class which inherits from super-classes is called a Sub-class
  • Super-classes are sometimes called ancestors as well
  • Object-oriented design can also feature multiple inheritances, which allow a subclass to inherit functionality from multiple parent classes
Routine/Procedure
  • In computer programming, routine and subroutine are general and nearly synonymous terms for any sequence of code that is intended to be called and used repeatedly during the execution of a program – code re-use
    This makes the program shorter and easier to write (and also to read when necessary). Short piece of code does not necessarily imply it is easier to read.
  • A function is a named procedure that performs a distinct task
  • Functions are sometimes called library routines (especially, those inbuilt in the language core)
Assembler
  • An assembler is a program that takes basic computer instructions and converts them into a pattern of bits that the computer's processor can use to perform its operations
  • Some people call these instructions assembler language and others use the term assembly language
Composition
  • So far, we've learned to design systems as a group of interacting objects, where each interaction is viewing the objects involved at an appropriate level of abstraction
  • Composition is the act of collecting together several objects to compose a new one
  • Composition is usually a good choice when one object is part of another object
Polymorphism
  • Is the ability to treat a class differently depending on which subclass is implemented
  • The ability of different objects to respond, each in its own different way, to identical messages
Refactoring
  • Is an essential process in the maintenance of a program or design
  • The goal of refactoring is to improve the design by moving code around, removing duplicate code or complex relationships in favor of simpler, more elegant clean, readable designs
UML

The Unified Modeling Language is a general-purpose modeling language in the field of software engineering, which is designed to provide a standard way to visualize the design of a system.

Summary:

The important thing to bring from all these definitions is to make our models understandable to the other objects that have to interact with them.
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5214
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#3

TSSFL -- A Creative Journey Towards Infinite Possibilities!
Post Reply

Return to “Java Programming”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 0 guests