1/33
COMPLETE
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is a class?
a template defining methods & attributes used to construct a set of objects
What are objects?
program building blocks
self-contained instances of classes based on real world entities which contai attributes & methods
What is a method?
a subroutine that forms the actions an object can carry out
What is an attribute?
a data value stored in a variable associated with an object
What is the purpose of a constructor?
creates an instance of an object from a class
What does OOP attempt to do?
capture/group information,data & code into structured items known as objects
What are the three sections of a class?
class name
attributes
methods
What are two advantages of OOP?
allows for code reusability
easier to modify + maintain programs
What is instantiation?
process of creating an object from a class template
What is the constructor used in psuedocode?
new
What is the constructor used in python code?
__init__
Why is the word “private“ used to define attributes in psuedocode?
this means that no one can access and change the attribute (only can do this through get and set)
What does a get method allow us to do?
allows attribute to be accessed/returned
What does a set method allow us to do?
allows attributes to be changed (w/ parameters)
In psuedocode what do you have to write at the end of every class?
endclass
What happens to the parameters when the object is instantiated?
the constructor method takes values of parameters and sets it to local attributes
What is inheritance used for?
quickly & easily reuse code from the superclass
extend attributes & methods without affecting the original code
Define inheritance
when a class takes on methods & attributes of a parent class
What may the inheriting class do?
overide some methods/attributes
may have additional methods/attributes
What is the keyword used to override and get something from the parent class?
super
What is a super class/parent class?
the original template that is inherited from
What are the classes that inherit from the superclass/parentclass called?
subclass/childclass
What is encapsulation?
process of hiding data by keeping an object’s attributes private
values can only be directly accessed & changed via public methods (defined for the class and not from outside the class)
What does encapsulation maintain?
data integrity
What does encapsulation prevent?
indiscriminate, unexpected changes to attributes(could have unforeseen consequences)
What is polymorphism?
objects of different types can be treated in the same way
What does polymorphism allow?
allows same method to be applied to objects of different classes
What is an example of polymorphism using an array?
an array with objects of different classes having the same method to all of them
What is an advantage of polymorphism?
reduced volume of code produced - same code able to handle different objects
What is an example of polymorphism using a class diagram?
all of the classes may have the same method name “makeSound()” however they may all output different things depending on the class they’re in
What are the 4 modes of addressing?
immediate
direct
indirect
indexed
What are advanatages of OOP?
code reusability
classes used in other programs
inheritances extends upon existing classes
easy maintainability
classes can be modified/extended
debugging easier as encapsulation limits how attributes changed
more secure code
encapsulation - attributes can only be accessed/changed via public methods
better coding for team
classes can be distributed between team members
How could OOP be applied to a linked list?
class declaring attributes + methods for linked lists - intialise the nodes & join them
each time new node = create new object from class
subclasses can take on attributes + emthods from base class & also override + add
encapsulation used by using get & set to ensure nodes are only changed in intended way
How could OOP be applied to a video game?
call on classes per type of player/enemy object
one enemy/player class may generate many enemy/player objects w/ diff value attributes
special types of player/enemy objects can inherit from parent classes + allow for additional attributes
polymorphism allows attributes/methods of player/enemy objects to behave differently from normal if required