0% found this document useful (0 votes)
6 views5 pages

D.1 Oop-1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

D.1 Oop-1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

D.

1 OOP
Object - an abstract entity describing the data it contains (known as
properties or attributes) and the actions it can perform (known as methods)
Class - a template for an object, containing definitions for characteristics of an
object but no values assigned to it
Difference between class and instantiation of class - M23 marking scheme

Method - the actions associated with an object


UML relationships
Association - one object uses or is part of another object, but both can
exist independently.
a company uses (hires) an employee and an employee is part of a
company, but both can exist without the other
Denoted by a solid line

Dependency - one object requires another object in order to function


a vehicle requires an engine to operate. if the engine stops working
the vehicle cannot operate
Denoted by a dashed line ending with an arrow pointing towards the
class that is required

Aggregation - one object belongs to another object and none other, but
both can exist independently.
a guest can only be assigned to one room and none other, but both
can exist without the other
Denoted by a solid line beginning in a diamond

Inheritance - one object (subclass) is a specialized form of another object


(superclass)
a gas engine and an electric engine can both drive a car, but have
different characteristics
dependencies decrease the ability of code reuse and increase
maintenance overheads, so they should be kept to a minimum
Primitive datatypes in java - integers, floating-point decimals, characters,
boolean.
Primitive - a basic/pre-defined data type provided by the programming
language
Byte - integer. -128 (-2^7) to 127 (2^7-1). occupies 8 bits of memory
Short - integer. -32768 (-2^15) to 32767 (2^15-1) . occupies 16 bits of
memory
Int - integer. -2^31 to 2^31-1. occupies 32 bits of memory
Long - integer. -2^63 to 2^63-1. occupies 64 bits of memory
Float - decimal. occupies 32 bits of memory. not very precise
Double - decimal. occupies 64 bits of memory. more commonly used to
represent decimals as it is more precise
Char - character. 0 to 65535. occupies 16 bits of memory. represents a
Unicode character
Boolean - represents true or false. occupies 1 bit of memory
String - not a primitive datatype. a series of characters
Encapsulation - the inclusion of both data and actions into a single
component
classes contain both data (attributes) and actions (methods)
some data in a class can only be read (accessed) or modified (mutated)
outside the class using specific methods
Advantages of encapsulation - M23 marking scheme

Inheritance - to derive and extend / specialize a new class from an existing


class
Advantages of inheritance - M23 marking scheme

Polymorphism - where one method can give different outputs depending


based on the different contexts in which it is called
Static polymorphism - method overloading - if a method has different
arguments but the same name, it may return different values as the
output
Dynamic polymorphism - method overriding - a method of the in a
subclass may override the actions of the method of the same name in
the superclass and return a different output

advantages:
object actions may have the same name but different parameters
returning different outputs
subclasses may have their own unique actions and are able to
override superclass actions
disadvantage of OOP - for smaller projects, OOP may increase complexity,
development time and maintenance costs
Definitions
Instance variable - the specific value of a variable in an object
Parameter variable - the data items passed to a function as a parameter
Local variable - a variable declared within a block of code that are only
usable
Accessor - a method that is used to read the value of a variable of an
object. used if the object is private
Mutator - a method that is used to modify the value of a variable of an
object. used if the variable is private
Constructor - a method that is called when an object is instantiated.
usually used to initialize the variables of the object
Return value - the value that is passed back once a method is executed.
if the return type is void, no value needs to be returned
Access modifiers
Private - only accessible by the class that defines it
Protected - only accessible by the class that defines it, and subclasses
that extend from it
Public - accessible by any class
Extends - indicates that one class inherits from another class
Static - a value that belongs to the class itself and not the objects of the
class. the value is the same across all objects even when modified
Static variable - M23 marking scheme

You might also like