OOP design Flashcards

1
Q

Scanner

A

The scanner begins the analysis of the source
program by reading the input, character by
character, and grouping characters into
individual words and symbols (tokens)

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

Parser

A

Given a formal syntax specification (typically
as a context-free grammar [CFG] ), the
parser reads tokens and groups them into
units as specified by the productions of the
CFG being used.
➢As syntactic structure is recognized, the
parser either calls corresponding semantic
routines directly or builds a syntax tree.

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

Semantic Routines

A

Perform two functions
◼ Check the static semantics of each
construct
◼ Do the actual translation
◼ Intermediate representation is the representation
of the program in a language internal to the compiler

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

Optimizer

A

The IR code generated by the semantic routines is
analyzed and transformed into functionally equivalent
but improved IR code
This phase can be very complex and slow
->loop optimization, register allocation, code scheduling

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

Code Generator

A

➢Interpretive Code Generation
➢Grammar-Based Code Generator

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

Primitive vs Non-primitive (Object)

A
  • Primitive types are predefined in Java.
  • Non-primitive types are created by the programmer
    and is not defined by Java (except for String).
  • Non-primitive types can be used to call methods to
    perform certain operations, while primitive types
    cannot.
  • A primitive type has always a value, while non-
    primitive types can be null.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A collection is a unit

A

that contains a group of objects, e.g.,
a list of students …
* Java defines a collections framework since JDK 1.2,
which is a unified architecture for representing and
manipulating collections, allowing them to be
manipulated independent of the details of their
representation.
* Java collections framework contains:
* Interfaces
* Implementations
* Algorithms

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

Benefits of Java Collections Framework

A
  • Reduced Development Effort – It comes with
    almost all common types of collections and
    useful methods to iterate and manipulate the
    data.
  • Increased Quality – Using core collection
    classes that are well tested increases our
    program quality rather than using any home
    developed data structure.
  • Reusability and Interoperability
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

public interface Iterable<T></T>

A
  • T - the type of elements returned by the iterator
  • Implementing this interface allows an object to be the
    target of the “for-each loop” statement, i.e., allows it
    to be iterated
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Iterators

A

An Iterator is an object that enables you to traverse
through a collection and to remove elements from the
collection selectively, if desired. You get an Iterator for
a collection by calling its iterator() method. The
following is the Iterator interface.

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

Overriding (via inheritance)

A

Replacing an inherited method with another having the same signature

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

Overloading

A

Two or more methods with different signatures

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

Inheritance is transitive

A

An instance of class Parrot is also an instance of Bird, an instance
of Animal, …, and an instance of class Object

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

Overriding by Replacement

A

Defining Methods in the Child Class:
Overriding by Replacement
* A child class can override the definition of an inherited method in
favor of its own
* that is, a child can redefine a method that it inherits from its parent
* the new method must have the same signature as the parent’s method,
but can have different code in the body
* In java, all methods except of constructors override the methods of
their ancestor class by replacement. E.g.:
* the Animal class has method eat()
* the Bird class has method eat() and Bird extends Animal
* variable b is of class Bird, i.e. Bird b = …
* b.eat() simply invokes the eat() method of the Bird class
* If a method is declared with the final modifier, it cannot be
overridden

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

Overloading vs. Overriding

A
  • Overloading deals with
    multiple methods in the
    same class with the same
    name but different
    signatures
  • Overloading lets you
    define a similar operation
    in different ways for
    different data
  • Overriding deals with two
    methods, one in a parent
    class and one in a child
    class, that have the same
    signature
  • Overriding lets you define
    a similar operation in
    different ways for
    different object types
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Multiple Inheritance

A
  • “diamond problem”, where it may be ambiguous
    as to which parent class a particular feature is
    inherited from if more than one parent class
    implements the same feature.
  • Java doesn’t support Multiple Inheritance, i.e.,
    can not extends more than one superclass
  • C++, Perl, Python support multiple inheritance
17
Q

Superclasses are created through the process called
“generalization”

A

What is an Abstract class?
Superclasses are created through the process called
“generalization”
Common features (methods or variables) are factored out of object
classifications (ie. classes).
Those features are formalized in a class, i.e., superclass
The classes from which the common features were taken become
subclasses to the newly created super class
Superclass does not have a “meaning” or does not directly
relate to a “thing” in the real world
It is an artifact of the generalization process
Because of this, abstract classes cannot be instantiated
They act as place holders for abstraction
Abstract classes are used heavily in Design Patterns
Creational Patterns: Abstract class provides interface for creating
objects. The subclasses do the actual object creation.
Structural Patterns: How objects are structured is handled by an abstract
class. What the objects do is handled by the subclasses.
Behavioural Patterns: Behavioural interface is declared in an abstract
superclass. Implementation of the interface is provided by subclasses.
In general: When one needs to generalize (abstract, factor out) common
properties and/or behaviours of conceptually related classes
Be careful not to overuse abstract classes
Every abstract class increases the complexity of your design
Every subclass increases the complexity of your design
Ensure that you receive acceptable return in terms of functionality given
the added complexity.

18
Q

Abstract Methods

A

Methods can also be abstracted
An abstract method is one to which a signature has been provided, but no
implementation for that method is given.
An Abstract method is a placeholder. It means that we declare that a
method must exist, but there is no meaningful implementation for that
methods within this class
Any class which contains an abstract method MUST also be
abstract
Any class which has an incomplete method definition cannot be
instantiated (i.e., it is abstract)
Abstract classes can contain both concrete and abstract
methods.
If a method can be implemented within an abstract class, and
implementation should be provided.

19
Q

What is an Interface?

A

An interface is similar to an abstract class with the following
exceptions:
All methods defined in an interface are abstract. Interfaces can contain no
implementation.
Interfaces cannot contain instance variables. However, they can contain
public static final variables (ie. constant class variables)
*Note: this is changing in the latest versions of Java. In this course, we maintain the
traditional definition of the interface.
Interfaces are declared using the “interface” keyword
If an interface is public, it must be contained in a file which has
the same name.
Interfaces are more abstract than abstract classes. There is no
hierarchy among them. Interfaces can extend other interfaces.
This creates a parent-child hierarchy.
Interfaces are implemented by classes using the “implements”
keyword.
A Class can only extends from one superclass. However, a
class may implement several Interfaces
The interfaces that a class implements are separated by commas
Any class which implements an interface must provide an
implementation for all methods defined within the
interface.
NOTE: if an abstract class implements an interface, it NEED NOT
implement all methods defined in the interface. HOWEVER, each
concrete subclass MUST implement the methods defined in the
interface.
An interface can extend multiple interfaces
Interfaces can inherit method signatures from other interfaces

20
Q

Abstract Classes Versus Interfaces

A

Abstract Classes Versus Interfaces
When should one use an Abstract class instead of an
interface?
If the subclass-superclass relationship is genuinely an “is a”
relationship.
If the abstract class can provide an implementation at the
appropriate level of abstraction
When should one use an interface in place of an
Abstract Class?
When the level of abstraction of the methods is such that they
can be used by a huge variety of other abstractions
When the subclass needs to inherit from another class
When you cannot reasonably implement any of the methods

21
Q
A