OOP Flashcards
class
template for an object, defining the attributes and behaviours/methods of the objects in the class
attributes/instance variables
data associated with a class
behaviour/methods
functionality of a class: something that it can do or can be done with it
OOP
composed of a number of interacting objects, each of which is responsible for its own data and the operations on that data. Program code creates the objects and allows them to communicate and receive answers. All processing that is carried out in the program is done by the objects
information hiding
when a class cannot directly access the attributes of another class when they are declared private
why are attributes generally private and classes generally public
so classes can use methods belonging to other classes but cannot directly access or change their attributes
constructor
procedure used to create objects in a class
instatiation
the creation and naming of a new object in a particular class
keyword: new
used when declaring a constructor and instantiate a new object in a class
reference (type) variable
named memory location in which you can store information. it holds a pointer or reference to where the object is stored
in a variable reference diagram the circle and rectangle refers to..
circles: reference variables
rectangles: primitive data types
what are messages used for
to examine or change an object’s state
getter messages
written as functions which return an answer
setter messages
written as procedures which can change the state of an object
objects
instances of a class, which have the same structure methods and attributes but their own data.
encapsulation
both the data and methods are stored with an object in a single entity so the behaviour and methods of one object does not affect how another object functins
whats so good about encapsulation
programmers can work on different parts without worrying how their code will affect others.
programmers can use methods from other classes without worrying about how they work
variable reference diagram
shows in graphical form an object referenced by a reference variable
inheritance
when a subclass inherits/shares attributes/methods with its superclass but with their own data and extra methods.
what does in inheritance diagram look like
has unfilled arrows pointing up towards superclass
polymorphism
refers to a programming language’s ability to process objects differently depending on their class, despite methods having the same name.
overriding
defining a method with the same name and formal argument types as an inherited method from a superclass
code: defining a class and attributes
class Animal
private name
private position
code: defining a procedure
public procedure new ( x, y, z)
aX = x
endprocedure
(new only if constructor)
code: an object which is inheriting another objects properties
class mouse inherits Animal private squeakNoise public function squeak ... endfunction
how to access private attributes of another object
through functions/procedures: getter/setter
if you want to use superclass’ methods, eg called stackSize, how do you do this
super.new(Stacksize)