Option D Flashcards
(39 cards)
Outline the general nature of an object.
In general an object can be defined as a location in memory having a value. This could be a variable or data structure. Usually when talking about objects it refers to instances of a class.
What are the three rows of a UML diagram?
- Class name
- Variables
- Methods
What is the structure of a variable in a UML diagram?
varName : type ( = value)
What are the three types of relationships between objects?
The three types of relationships that should be known are dependency (“uses”), aggregation (“has a”) and inheritance (“is a”).
Explain aggregation.
Aggregation is a type of relationship between objects. It means that one type of object contains another or is composed of another. Some examples are: a car has-an engine, a bicycle has-a wheel, and a coffee cup has coffee.
Explain inheritance.
Inheritance is a type of relationship between objects. It means that one type of object is a more specific version of a general type. Some examples are: a car is-a vehicle, a bicycle is-a vehicle, and a coffee cup is-a cup.
Explain dependency.
Dependency is a type of relationship between objects. It means that during some activity, one type of object uses another type of object. Some examples are: a car uses-a squeegee (during a window-washing activity), a bicycle uses-a pump (during a tire-pumping activity), and a coffee cup uses-a stirrer (during a stirring activity).
How are dependency and aggregation represented in a UML diagram with multiple classes?
In UML: A dependency (when one dies, the other dies) is represented by a shaded diamond
An aggregation is represented by a hollow diamond
What are the two parts of an object?
- Attributes (variable names)
2. Behaviour (Methods)
What are the four fundamental OOP concepts?
- Encapsulation
- Abstraction
- Inheritance
- Polymorphism
Encapsulation and abstraction are _____ concepts.
Complementary
What’s the major difference between abstraction and encapsulation?
Just like abstraction, encapsulation hides data, but at a deeper level.
What is encapsulation?
Encapsulation is the process of combining data and methods into a single unit (class). In Encapsulation, the data is not accessed directly; it is accessed through the methods present inside the class. In simpler words, attributes of the class are kept private and public getter and setter methods are provided to manipulate these attributes. Thus, encapsulation makes the concept of data hiding possible.
What is inheritance?
Inheritance enables programmers to define an “is-a” relationship between a class and a more specialized version of that class. For example, if a Student class extends a Person class, then it should be the case that Studentis-aPerson. The subclass Student builds on the functionality of the superclass Person.
If a parent class is shapes, list some child classes it can have?
triangle, rectangle etc.
What is polymorphism? What are the two types?
Polymorphismrefers to a programming language’s ability to process objects differently depending on their data type or class. The two types are method overloading and method overriding.
Describe method overriding.
Method overriding is a type of polymorphism that allows a subclass or child class to provide a specific implementation of amethodthat is already provided by one of its superclasses or parent classes. Method overriding allows a sub class to use all the general definitions that a super class provides and add specialised definitions through overridden methods.
Describe method overloading.
Method overloadingis a type of polymorphism that allows a class to have two or moremethodshaving same name, if their argument lists are different. Method overloading allows methods that perform similar or closely related functions to be accessed through a common name.
What is the main advantage of encapsulation?
The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this feature, encapsulation gives maintainability, flexibility and extensibility to our code.
List 3 advantages of inheritance.
- Reusability - ability to use public methods of base class without rewriting the same
- Extensibility - extending the base class logic as per business logic of the derived class
- Data hiding - base class can decide to keep some data private so that it cannot be altered by the derived class
- Space saving
List 2 advantages of polymorphism
- Method overloading can be used so that we do not have to find alternative and meaningful names for two methods that perform the same things with slight differences (e.g. different data types)
- Method overriding works together with inheritance to enable code reuse of existing classes without the need for re-compilation.
What are libraries?
Pre-defined sets of codes that could be used.
Why are libraries useful?
The main advantage of using libraries of objects is so that sorts and other complex algorithms and processes do not have to be “re-invented”, thus saving time.
List 3 disadvantages of OOP.
- May not be useful for very simple procedures
- Larger file size
- Slower
- Steep learning curve