Option D: Object Oriented Programming in Java Flashcards
Outline the general nature of an object.
An object is an abstract entity that describes the data the entity has (properties, attributes, or instance variables) and the actions that this entity can perform (methods).
Distinguish between an object (definition, template, or class) and instantiation.
A class is a template that describes the data and actions an entity might have, but does not contain any specific data itself. An instantiation is a specific object created from the template. For example, a Vehicle class might describe the properties (make, model) and actions of the Vehicle (drive, refuel), but an instance of a Vehicle represents a specific car (e.g. make: “Toyota”, model: “Corola”)
Construct unified modeling language (UML) diagrams to represent object designs.
Place the class name in the top box, the instance variables or data in the box below (include data types), and the actions or methods in the box below that.
Represent object relations using UML diagrams.
Arrows represent inheritance (“is a”) and diamond arrow heads represent composition and aggregation (“has a”)
Describe the process of decomposition into several related objects.
Example: A Company object may have an Employer and Employee objects that each inherit from a Person object. The Company also has a Budget object since the company adheres to a budget.
Describe the relationships between objects for a given problem.
Aggregation: “has a” relationship. One object belongs to another object.
Inheritance: “is a” relationship. One object is a specialized form of another object.
Outline the need to reduce dependencies between objects in a given problem.
The more that objects depend on one another, the system becomes less modular and harder to maintain. Modifying one object would require us to modify the objects that depend on it as well. Reducing the number of dependencies makes systems more flexible.
Construct related objects for a given problem.
Example: A store sells different kinds of Vehicles and needs to develop a computer program to keep track of all its vehicles that have common and unique characteristics.
Explain the need for different data types to represent data items.
int (integers) represent whole numbers, real numbers or floating points (float or double) represent numbers with fractional values, booleans (true or false), Strings (text)
Describe how data items can be passed to and from actions as parameters.
Parameters allow data to be input into methods, enabling dynamic behavior. E.g., getPriceWithTax(double rate). The parameter is the name defined in the method (rate). The argument is a value passed into a method when it is called. (e.g. getPriceWithTax(7.2) the argument would be 7.2)
Define the term encapsulation
The inclusion of both data and actions ina single component. Classes contain use public/private fields and methods to only give the user of the class access to specific data and actions.
Define the term inheritance
A relationship where one object (the child of subclass) is a specialized form of another object (the parent or superclass). The derived object inherits the data and actions of the superclass.
Define the term polymorphism.
Polymorphism allows objects of a derived class to be used in place of their superclass. For example, if the class Dog inherits from a class Animal, anywhere Java expects an Animal object, we could use a Dog object instead, since it is a specialized form of the Animal class.
Explain the advantages of encapsulation.
By making data and actions only accessible in a predefined way: data can be made read-only or write-only, a class can restrict the way that data can be altered (i.e. add validation logic), a class can hide the way data is stored so that implementation can change without affecting how the class is used (this makes the class easier to maintain).
Explain the advantages of inheritance.
Extensibility: a subclass can extend or redefine functionality of a parent class
Reusability: a child class will reuse code from the parent class, any changes to common behavior only needs to be done once in the parent class
Information hiding: the parent class can determine what actions and data are available to child classes
Overriding of actions: child classes may override parent actions in order to implement meaningful actions for their needs
Explain the advantages of polymorphism
Allows subclasses to have their own unique actions as well as being able to override or improve on parent actions.
Allows subclasses with different behavior to use a common interface (for example different subclasses of an Animal class may all have the makSound method; which can be called without having to know which object implements the specific action)
Explain the advantages of using libraries of objects.
Allow for code reuse, application developers do not need to rewrite code for common functionality. Can be used as an “balck box” without having to understand the implementation. Examples include various built-in Java classes: Scanner, Random, ArrayList, Arrays, etc.
Describe the disadvantage of object oriented programming.
For small projects, may lead to unecessary complexity and overhead. When used improperly can introduce uneeded levels of abstraction making development more cumbersome and programs more difficult to understand.
Discuss the use of programming teams.
Programming in teams can provide the following advantages: larger projects can be taken on, more developers bring more diverse ideas, the strengths and weaknesses of various team members may offset each other, team members do not need ot know the workings of the whole project and can concentrate their time and energy on a specific portion.
However, to work successfully, developers need well-managed communication system between developers. Project planning takes longer compared to a single developer project.
Explain the advantages of modularity in program development.
Modularity is the process of dividing a program into separate, smaller sub-programs that can be implemented or tested on their own before combining them togethre. Modularity provides the following advantages:
A sub-program used for one application can be reused for another.
Different developers or teams can work on sub-programs in parallel.
Programs that are comprised of short, simple and easy to understand smaller sub-programs are easier to understand, maintain and debug.
Define the term “class”
Defines a template, including data (fields, attributes, instance variables) and actions (methods) from which objects may be instantiated. For example, a Person class may describe template for a Person object including data like a name, a height, and an age. This class can be instanced to represent a specific person (e.g. “Mike” with height 1.8m, and age 25)
Define the term “identifier”
A name that identifies an entity, e.g. a class name, a variable name, the name of a method.
Define the term “primitive”
Common data types that are available in most programming languages as basic building blocks. Includes characters (char), integers (int, short, long), floating point numbers (float, double), and Booleans (boolean)
Define the term “instance variable”
Data unique to a specific instance of an object. For example, a Person class may define a name, height, and age as instance variables, but their values will be different to each specific instance of the Person class created.