Object Oriented Programming Flashcards
The structure
Can store different types of data.
Cannot define a function within a structure, only reference them.
Object
Instance of a class ( one knight in particular)
Class
Template for objects
Only define / initialize variables / functions that are general to all instances of that class.
Four main principles of object oriented programming
Encapsulation
Abstraction
Inheritance
Polymorphism
Encapsulation
Bundling data and methods that can operate on that data within a class. Nothing outside the class can interact w/ data within it.
Must interact through its methods
Generally, best to not allow external classes to directly edit an object’s attributes
In complex projects good to not rely on every piece of the project or let pieces become entangled.
Getting Methods
Retrieving information
Setting Methods
Changing information
Information hiding
Keeping data of one class hidden from external classes.
Helps control the program and prevent it Frome becoming too complex.
Abstraction
Only showing essential details, hiding everything else.
I.e. understanding the outcome, but not the full process ( driving a car vs. building a car).
If one class is changed, do not need to change everything that interacts with it.
Interface
Way sections of code can communicate with one another
Implementation
How methods are coded (hidden)
Inheritance
Principle that allows classes to derive from other classes.
Ex. Weapons class | sword class vs. club class
Superclass to sub classes
Access modifiers
Changes which classes have access to other classes, methods, or attributes.
Three main access modifiers
Public
Private
Protected
Inheritance - Public
Can be accessed from anywhere, superclass, subclasses or other parts of the program.
Inheritance - Private
Only be accessed from the same class that the member is defined.