![]() |
Created by Malachy Moran-Tun
almost 3 years ago
|
|
Question | Answer |
What is a Class? | > Template or "blueprint" for an object > Contains the state (i.e., the attributes) and behaviour (i.e., the methods) of an object > An object is an instance of a class |
What are Attributes and Methods? | > Attributes - variables that are assigned by the class, or when the object is instantiated give an object properties > Methods - subroutines that make up the actions an object can perform |
What is an Object? | > A unique instance of a class > A class is a blueprint for many different types of object (e.g., class "Animal" may have "Dog", "Cat", and "Lynx" objects) > All objects will have the same attributes and methods as the class > Objects are created using classes through instantiation |
What is Inheritance? | > Child (sub) classes can inherit the methods and attributes of parent (super) classes > Child classes can have additional methods and attributes, as well as those inherited from parent classes > For example, "Animal" -> "Mammal" - the "Mammal" class is still a blueprint for a variety of objects, but it's related to the entire animal class |
What is Polymorphism? | > Allows for a programming language to process objects differently, depending on their class > Allows for child classes to override parent class' methods and attributes (i.e., if the child class had a method that was named the same as the parent class' method, it would use the child class') |
What is Encapsulation? | > Setting methods and attributes to private or public > Private attributes can only be access through (public) set and get methods in the class > Private attributes are used to prevent accidental changes to attributes |
What is a Constructor? | > Special procedure that allows the class to create objects > General pseudo-syntax is as follows: public new ObjectName(attribute1, attribute2...) { this.attribute1 = attribute1 this.attribute2 = attribute2 etc. } |
How do you Instantiate an Object in Code? | Pseudocode: variableName = new objectName(attribute1, attribute2...) |
What are the Advantages of Object Oriented Programming? | > Forces a planning phase, which generally makes for better, easier to manage designs > Encapsulation: the code can be written, tested, and maintained independently, since nothing will be altered elsewhere in the code > Knowledge on how an object's methods work is not needed to use the object > New objects can have small differences > Objects (that have been already coded and tested) can be used in many different programs (reusable) > OOP automatically breaks down the problem into smaller sub-problems (decomposition) > OOP lends itself to teams - each member can focus on one object |
What are the Disadvantages of Object Oriented Programming? | > Steep learning curve - the process of OOP is not as easy to understand as other programming, since knowledge of classes, objects, methods, attributes, encapsulation, polymorphism etc. is required for OOP to be useful > Larger program size - programs generally involve more lines of code (albeit code that can therefore be reused easier) > Slower programs - programs generally require more instructions to be executed > Not suitable for all types of problems |
There are no comments, be the first and leave one below:
Want to create your own Flashcards for free with GoConqr? Learn more.