Midterm 1 Flashcards

1
Q

Object Oriented Design

A

The attributes and behaviors are contained within a single object, whereas in procedural, or structured, design, the attribute and behaviors are normally separated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why use objects

A

(1) Writing code that can be easily modified and extended.
(2) Making it difficult to make certain kinds of errors when writing code.
(1) Improve testability.
Overall, reduce the probability that the program will have certain kinds of bugs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an object

A

has specific data attributed to it and unique functions associated with it. For instance, a student Object might have W-Number, gender, DOB, SSN, etc. and would have behaviors where we could getCalculateGPA, getCoursesTake, setCGPA etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a class

A

A blueprint, template, cookie cutter for an object. When we use new Student(x, y, z) a new student object will be constructed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Things Described by a class

A

Attributes: Name, type, whether or not the attribute is externally visible.
Methods: Name, parameters, return values, whether they are public or private.
Constructors: methods that are used to initialize new objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Encapsulation

A

Bundling data and behavior together in an object so that only the external behavior is exposed.
from the perspective of client classes, the external behavior can be thought of as what the object “does” or what the object is “responsible” for.
Some Authors consider information hiding and encapsulation as being synonymous.
Others consider information hiding as the principle and encapsulation as the programming language mechanism.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Inheritance

A

Idea: the child inherits both interface and implementation from the parent.
Inheritance: IS-A relationship
a manager is an employee and an employee is a person. etc.
Anything that can be done to the person can be done to the the employee and then onto the manager.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Polymorphism

A

Type (1): Multiple functions with the same name. The actual function invoked is chosen based on types of the parameters as determined by the compiler at compile time. i.e. System.out.print can print has nine different version.
Type (2): In OO there are Multiple function that have the same name and signature but the actual function invoked is chosen during the run-time, wherein it is chosen based on the actual type of the parameter(s).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Polymorphism: Overloading

A

Multiple functions which are distinguished by the compiler based on the type of the parameters.
e.g. toString(String x), toString(int x), toString(int x, int y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Polymorphism: Overriding

A

When the implementation of a function in a child is used instead of the implementation of the “same” function in a parent, the function in the child is said to override the implementation in the parent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Composition: HAS-A relationship

A

Composition is when one object “contains” or HAS-A another.

Eg. a car HAS-A engine and the engine IS-A Engine4Cyl or IS-A Engine6Cyl.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Constructors in OO

A
Constructors are methods that share the same name as the class and no return type.
e.g. we have the method public Student(int x, int y)
when we call the method
Student Bob = new Student(4, 3) the Student method constructs the new student object bob that has the specified attributes created in the student object. 
The constructor will allocate memory for the new object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Default constructor

A
If the case of absence of a constructor, the class will still compile. 
If the class provides no explicit constructor, a default constructor will be provided by the compiler. 
Besides the creation of the object itself, the only action that a default constructor will take is to call the constructor of its superclass.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Method Overloading

A

Overloading allows a programmer to use the same method over and over, as long as the “signature” of the method is different each time.
Signature = method name + parameter list
public int getCGPA(String WNum)
public int getCGPA(int WNum)
public int getCGPA(String WNum, String level)
Note:
In Java and C# the return type is not part of the signature. the following methods would conflict even though the signature is the same.
public int getGPA(string WNum, String Level)
public String getGPA(String WNum, String Level)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Ways of Error Handling

A

Ignore the Problem–Not a good idea! (crying is better)
Check for potential problems and abort the program when you find a problem. (Use print functions everywhere)
Check for potential problems, catch the mistake, and attempt to fix the problem. Implementing something like peekFirst or getFirst in the Deque class)
Throw an exception. (In general, preferred way)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Scope

A

Multiple objects can be instantiated from a single class.
Each of these object has a unique identity and state. Each object is constructed separately and is allocated its own separate memory.
Attributes and methods exist within a particular scope.

17
Q

Local Attributes

A

Local attributes are owned by a specific method

18
Q

Object Attributes

A
There are many design situations in which an attribute must be shared by several methods within the same object. When the variable is instantiated before the other methods/ processes.
public class Number {
     int count = 0;     ---->    (object attribute)
     public void method1(){
           int count;     ---->     (local attribute)
     public void method2(){
           int count;     ---->    (local attribute)
19
Q

Class Attributes

A
Two or more objects can share attributes and in Java and C# we do this by making the attribute static. 
Class attributes are allocated a single piece of memory for all objects instantiated from the class. Thus all objects of the class use the same memory location.
Each class has a single copy, which is shared by all objects of that class. e.g. Global Data in OO Design. Need to be careful of synchronization.
20
Q

Multiple Inheritance

A

Allows a class to inherit from more than one class.
Is a very powerful technique and in fact, some problems are quite difficult to solve without it.
Can even solve some problems quite elegantly.
Can increase the complexity significantly
Not allowed in Java and .Net
Allowed in C++

21
Q

Class Name

A
Identifies the class itself.
Must be descriptive.
In java class names must be the same name as the file name.
22
Q

Class Attributes

A

Attributes represent the state of the object because they store the information about the object. I.e.
Student class has attributes:
private static String StudentName = “Daniel Tiger”
Private static String WNumber;
private Courses coursesTaken;
etc.

23
Q

Designing Attributes

A

Private attributes help in data hiding
this is in keeping with the design principle of keeping the interface design as minimal as possible.
The only way to access these attributes is through the method interfaces provided.

24
Q

Constructors

A
Are methods that share the same name as the class.
Have no return type.
A constructor for the student class will be 
public Student(){
        /* code to construct student object */
}
25
Q

Accessors

A

Accessors are sometimes referred to as getters and setters and sometime they’re simply called get() and set()
public void setName(String studentName){
name = studentName;
}

26
Q

Static Attributes and Setters

A
If an attribute is static, and the class provides a setter for that attributem any object that invokes the setter will change the single copy.
thus the value for the attribute will change for all objects.
27
Q

Identifying Public Interfaces

A
  1. A class should provide the behaviors that are required by the users.
  2. A class should only provide the behaviors by the users.
28
Q

Design Guideline: Design with Extensibility in Mind

A

Adding new features to a class might be as simple as extending an existing class.
i.e. adding a few new methods
modifying the behavior of others
it should not require to rewrite everything
If we have an Employee class we must consider the fact that we might later want to write a Staff Class. thus, having Staff inherit from Employee might be the best strategy; in this case, the Employee is said to be extensible.

29
Q

Cohesion

A

We should aim for high Cohesion. Cohesion indicates to what degree a programs or a components various tasks and responsibilities are related to one another, i.e. how much a program is focused on solving a single problem.
Two types of cohesion:
Strong Cohesion: each object should have a single responsibility.
Weak Cohesion: A class, which does many things at the same time, is difficult to maintain and understand.

30
Q

Coupling

A
We want to keep low coupling to help with maintainability. 
If one class depends on another, those two classes are said to be coupled. 
Some level of coupling is always present. 
High-Levels of coupling creates problems when software has to be changed to fix bugs and add new features. 
Using interfaces rather than actual classes helps to reduce coupling.
Client code is only coupled to the interface, not to the implementation.
31
Q

Cohesion

A
Coupling refers to the extent to which components are related to each other. 
In general in OO design each class should have a small cohesive set of responsibilities.
32
Q

Types of Cohesion

A

Functional: Components are grouped together because all components contribute to a single well defined responsibility or task.
Sequential: Components are grouped together because the output of one is input to another.
Communicational: Components that operate on the same data are grouped together.
Procedural: Components that perform the same sequence of operations are grouped together.
Temporal: components are grouped by when they are processed.
Logical: a logically cohesive module is one whose elemnts contribute to activities of the same general category. I.e. the java math package. it adds subtracts multiplies makes random numbers.
Coincidental: Components are collected together due to some arbitrary distinction such as common developer skill set or to avoid small modules.