You are on page 1of 13

Further

Object Oriented Programming


“FOOP”
Introduction
and Basic Aspects of OOP
ECS658U
Matthew Huntbach
matthew.huntbach@qmul.ac.uk

Part 1
1
Object Oriented Programming
Studied so Far
• You will have taken a 1st year module on Object Oriented
Programming, ECS414U, but that only gives a basic
introduction to the general concept of it
• You will have covered more on aspects of Object Oriented
Programming in the 2nd year module on Software Engineering,
but the that module did not concentrate on detailed aspects of
writing code
• Further study of how to write code was in the 2nd year module
Algorithm and Data Structures, but that module did not give
much emphasis on aspects of programming that come under
the principles of Object Oriented programming
• There are many important aspects of Object Oriented
Programming mentioned but not given detailed coverage so far

2
Professional Programmer Requirements
• Do a web search on “coding interviews” to see the sort of
requirements that would be needed for someone applying for a
job as a programmer
• What this means is that part of the interview for a job application
will involve being asked to write some code to solve a problem
• A coding interview often involves writing code by hand, as it is
considered that anyone who has proper understanding of
programming can do that
• Also look at Oracle’s Programmer Certification:
https://education.oracle.com/oracle-certified-professional-java-s
e-8-programmer/trackp_357
to see what they regard as necessary to show that you really
are someone who can program in Java, and their own test to
get a certificate to prove you have reached that level

3
Why Can’t Programmers … Program?
• See this link:
https://blog.codinghorror.com/why-cant-programmers-program/
for a famous article on people apply for programming jobs
• This article has been frequently quoted many times since it was
first put up on-line by one of the most famous commentators on
programming, Jeff Atwood
• The claim in it, following observations from others, is that the
vast majority of applicants for programming jobs “can’t write
code at all”
• It states that the majority of Computer Science graduates, when
asked to write some simple code in an interview, cannot do it
• It is for this reason that coding interviews take place

4
Further Object Oriented Programming
• So the main emphasis of the module ECS658U Further Object
Oriented Programming will be on writing actual code
• The emphasis will be on general aspect of writing code, moving
further from what you have studied in the 1st year module
ECS414U Object Oriented Programming
• It will go into more detail on the important aspects of good
quality code, Design Principles and techniques to meet them,
Design Patterns, that were covered in the 2nd year module
ECS505U Software Engineering
• So, where the emphasis of ECS505U was on showing structure
of code using UML diagrams, and using systems that can assist
in code development, ECS658U will concentrate just on writing
small pieces of code
• ECS658U will cover some of the further aspect of Java beyond
what was covered in ECS414U
5
Java
• For many years, Java was the dominant programming
language, the one most commonly used in professional
programming
• Java was seen as the best example of an object oriented
programming language
• Java was developed from a previous programming language C+
+ which had been successful because its object oriented
aspects were found to be useful for developing large scale code
• C++ was developed from a previous programming language, C,
by adding the object oriented features
• Java developed further from C++ by taking away its features
that were in conflict with the general principles of object oriented
programming

6
Python
• In recent years, the programming language Python has grown
in use and now challenges Java as the most used language in
professional programming
• Python has also become a common language for initial learning
of programming, in many cases replacing Java
• Although this growth of Python, challenging Java, has been
recent, Python like Java originated in the 1990s
• A big difference between Python and Java is that Python:
– Takes away the need to declare variables before they are
used
– Takes away the need to declare variables as having types
– So lets any method be called on any variable with any
arguments
• This is what makes Python code shorter and simpler

7
Java v Python
• While Python may seem simpler, because it does not have all
the complex aspects involving the use of variable types, that
also makes it harder to use to explain some of the aspects of
object oriented programming
• The use of types, though making code more complex, also
makes it clearer to see how different parts of code interact, and
enables errors to be discovered when the code is compiled
rather than only found out when it is run
• It is important to understand, however, that both Java and
Python are object oriented languages working by methods
being called on variables that represent objects
• So, while we will use Java to write code to illustrate concepts, it
is important to understand that many of the concepts we will
cover are general object oriented ones that apply also to other
programming languages, such as Python

8
Basic Aspects of
Object Oriented Programming
• The most basic aspect of Object Oriented Programming (OOP)
is that it is a way to divide code into parts
• As code becomes more complex, it becomes very hard to
understand how it works if it is not clearly divided into separate
parts, each of which is clearly defined
• What OOP is about is defining a type of object in terms of how it
interacts with other objects
• Interaction is done by calling a method on an object, or passing
it as an argument to a method
• A class gives the code that makes an object of that class do
what it is meant to do
• But you should be able to use an object just knowing it in terms
of how it interacts, not needing to know the details of the code
that makes it work that way
9
WHAT an Object does and
HOW it does it
• So it is important for code to be written in a way that makes a
clear distinction between WHAT an object does, which is how it
interacts with other objects through methods called on it, and
HOW it does it, which is the code inside it that makes the
methods work
• When you write the code for a class to provide objects that do
WHAT they are defined to do, you may decide they need
variables to store data needed to make them work, but those
variables should not be able to be accessed directly by code in
other classes
• If a variable added to provide HOW an object works could be
accessed and changed by code in another object of another
class, then it could no longer be guaranteed that the object
would work only in the way it was defined WHAT it would do

10
Object Content
• One aspect of what an object does is that a method can be
called on it, and it returns something
• A static method is one that is not called on an object, its
definition is what it just what it returns in terms of any arguments
passed to it
• A method which is not static is called an instance method, it
has to be called on an object and what it does is defined in
terms of the content of the object as well as its arguments
• The contents of an object in this case are part of its definition of
WHAT it does in terms of its interaction with other code, and not
the actual variables inside it that store how the content is
represented
• A method may change the content of the object it is called on
• A method may also change the content of objects passed to it
as arguments
11
Generalising Code
• Code should be generalised so that one piece of code can be
used in more than one place
• A class defining objects is an example: you can have several
objects of the same class, and one method which takes an
argument of that class and does something. Having the same
method used to manipulate the different objects, is better than
having to write separate code to manipulate each object
• However, more generalised code can be written that takes
objects of different classes because it only performs actions that
apply to objects of all the classes
• Having one piece of code that works for objects of different
classes is much better than having lots of pieces of code that
are almost identical apart from the classes of objects they take
• Generalised code should not be complicated by having to check
the details of the particular objects it is manipulating
12
Poor Quality Code
• The human user of some code does not need to know the
details of how it works internally, all that is required is that it
produces the right results
• However, code that is correct in that way is still poor quality if it
does not make the clear distinction between WHAT a piece of
code does and HOW it does it and/or if it is not generalised so
there is large amounts of code similar to other parts
• The reason for this is that poor quality code is more likely to
have errors where it is hard to find the errors and correct them
• Real used code often needs to be modified to add new features,
and that is much harder to do if it is poor quality
• Code which is written in a way that limits the interaction
between different parts is much easier to modify either to add
new features or to improve its efficiency
• Code which is generalised means modifying is less hard work
13

You might also like