Вы находитесь на странице: 1из 10

OBJECT-ORIENTED PROGRAMMING REVIEW CHECKLIST

I. BASIC DEFINITION
1. What is an object?
2. How an object is constructed?
3. How objects interact with each other?
4. What happen during object creation?
5. Constructors
a. Properties:
b. Cannot
c. Can
d. Type
i. No-argument: formal parameters
ii. Default: created by compiler if no constructor exists
iii. Parameterized
Note: Implementing only parameterized constructor but create a class
with no-arg will throw error.
6. Method call? Its components?
7. Methods? Components
8. Quality of methods: small, testable, readable, do one thing and do it well
9. Overload
10. Overriding
11. Access Modiifier
1. Class 2. Package 3. Subclass 4. World
b. Public x x x x
c. Protected x x x
d. Private x x x
e. No modifier x
12. Super vs This
- Super: allows us to access attributes and behavior of super class in inheritance
relationship
Must be the first line if it is used in a constructor
- This: refer to the object typed as the current class
o Allows us to differentiate between class and formal parameters
13. Inheritance
a. Def:
b. Keyword
c. No limit to the number of inheritance level
d. Does it violate encapsulation?
Yes. Inheritance allows subclass to access to the members of base class. A
change such as adding a new method in the super class that is overridden in the
subclass may lead to potential security risk. For example, if the purpose of
encapsulation is to protect program from outside behaviors, calling a method of
a superclass that is overridden in subclass would cause the program to behave
differently.
e. Why multiple inheritance is not supported in java?
Java supports multiple inheritance but not through classes, it supports only
through its interfaces. The reason for not supporting multiple inheritance is to
avoid the conflict and complexity arises due to it and keep Java a Simple Object
Oriented Language. If we recall this in C++, there is a special case of multiple
inheritance (diamond problem) where you have a multiple inheritance with two
classes which have methods in conflicts. So, Java developers decided to avoid
such conflicts and didn’t allow multiple inheritance through classes at all.
14. Abstraction
a. Def: hiding unwanted implementation details from the user.
b. Happens during design when deciding on what to implement
c. Focus on what the object does instead of how it does it
Hiding the unwanted data and giving relevant data
d. Achieved through abstract classes and interfaces
e. Outer layout, used in terms of design
f. Benefits:
i. Provide a generalization that can be built upon more specific classes.
ii. Ties together common behavior for related objects
iii. Separate the user and the coder
g. Example: Coffee: abstract with attributes: milk., sugar, shots..
15. Encapsulation
a. Def: wrapping data(attributes) and methods(behavior) into a single unity
Hide the internal working of the class from other classes and only accessible
through a public API
b. Happens during implementation
c. Hide the implementation (how it does it)
Means hiding the internal details or mechanics of how an object does
something so that we can change later without affecting outside client under
the assumption that the API will not change
d. Achieved through access modifier ( public, private, protected) and getters and
setters
e. Focus on inner layout, used in term of implementation
f. Ex: inner implementation of a mobile home: how keypad button and screen are
connect with each other using circuits
16. Abstraction vs Encapsulation vs Data Hiding
a. Abstraction provides a layer over basic functionalities. It hides the
implementation details, let users focus on higher idea
Achieved through abstract classes and interfaces
b. Encapsulation groups codes together on basic of functions into a class
Achieved through set attributes to private and provide public getters and setters
c. Data hiding: hides the data affected by the implementation
It uses private and public to control access to instance variables
Achieved through abstraction and encapsulation.
Provide data security by assuring that someone cannot accidentally modify a
variable.

17. Abstract class


a. May or may not contain abstract method
b. Can have a constructor
c. Must be declared abstract if contains abstract method
d. Cannot be instantiated. Why?
e. To use, must be inherited
f. Abstract methods declared in the abstract class are not implemented.
g. Can provide functionality

18. Interface
a. Contain method signatures
b. Methods are not defined
c. Static methods cannot be overridden
d. Define fields that can be accessed similarly to a static variable
e. Do not allow for constructor
f. Uses to group related methods with empty body
g. Signing a contract
h. Can implement multiple interfaces
i. Can extend another interface
19. Why programming to an interface?
20. Abstract class vs Interface

Abstract class Interface


Declare Must declare abstract if
contain abstract method
Instantiate No No
Constructor Yes No
Keywords Extends class Implements Interface..
Purpose to use An outline for a class Signing a contract
Provide functionality That all implementing classes must
through non-abstract perform behaviors defined in the
method interface
Must be inherited to use
it
Multiple? Can extends another Can implement M Inter using extends
abstract class CANNOT extends abstract
Can implement multiple
interfaces
Types of Abstract: not Before JV8: Abstract methods
methods implemented, must be
overridden Since JV9:
Non abstract  Abstract: are not defined,
must be implemented
 Default methods: provide
implementation, not
required to be implemented
or overridden, acted of
implementing class.
(potential diamond problem,
don’t know which method to
implement)
 Static method: cannot be
overridden, do not need to
be implemented, acted upon
the Interface
 Private method
 Private static

Types of var Static, non static Only static and final


Final, non final
Group related methods with empty
bodies
Fields Can define fields that similar to a
static var

21. Composition
a. Represents as has-a relationship
i. A Car IS-A VEHICLE (inheritance: Car extends Vehicle)
ii. A Car HAS -An engine( composition: engine is an attribute of car)
b. Focus on what the object is comprised of instead of what it is
c. Strongest form of association
i. When the object that holds the comprising object is destroyed, those
objs are destroyed as well.
d. When to use Inheritance or Composition?
e. Composition over Inheritance
f. Achieve by interface
g.
22.
(Left) The Person class represents a composition relationship between the Heart and Hand class.
(Right)The City class represents an aggregation relationship between the Tree and Car classes,
which can exist without the City class.

23. Aggregation
a. Has – a relationship where the child obj can exist independently of the parent
object
b. Represented by a data field in the aggregating class

24. Association
a. When two object interacts, there is an association
b. 1 – many, many-1, many-many
c. Comprise of composition and aggregation

Aggregation
Association
Composition

25. Exception and Error

Exception Error
Def Object program, that should not
catch because it may cover
up underlying problem
Type Checked/RuntimeE(unchecked) Unchecked
ex Checked: IO, FileNOtFound.. out of memory
Unchecked: NullPointer, Stackoverflow
IndexOutOfBound..

26. What is a call stack?


a. Def
b. What does it do?
c. Benefit
27. What happens during an exception?
28. Check and unchecked exceptions: def, how to handle, type, why it occurs
Checked Unchecked
Def Forces the implementer to Exception occurs at
specify or handle execution time but not
accordingly checked at compile time
When happen Compilation time Execution time
Ex FileNotfound, IO IndexOutOfBound,
NullPointer
IllegalState
Why Represent problems User error, not caught
outside of the immediate during implementation
control of the program:
database, files..
How to handle  Add throws
declaration
 Try/catch

29. Custom exception


a. Why it is created?
b. Condition to create?
c. What happen if we extend Exception?
30. Unit testing
a. Purpose
b. Forms of testing
c. Why test?
d. Does testing protect against small edge cases?
e. Junit testing
i. Def
ii. Best practice:
1. Target small unit code(method)
2. Business logic must be accompanied by tests
3. Have test classes for each class in application
f. Tests
i. assertEquals, Not Null, true, false…
31. Polymorphism
a. Def
i. Formal:
ii. Informal:
b. Benefit:
i. Allow the program to write code while only knowing about the base
class or interface ( list – arraylist)
ii. Promote code reuse
iii. Code becomes more modular and extensible
iv. Allow us to manage objects of different kinds of classes
c. Constraint
i. Cant assign a superclass obj into a subclass obj
d. Reference var:
i. Left handside
ii. Store the address of the subclass obj
iii. Polymorphic: able to refer obj of different types(subclasses)
e. Upcasting(Pug to Dog)
i. Def: An obj of a subclass can be treated as an obj of any superclass type
ii. Done automatically
iii. Not changing the obj, just label differently
iv. Benefit: program to an interface
v. Hides the specific implementation of the class being
upcasted(subclass):
1. Methods of the class being upcasted cannot be called
2. Unless the method being called is the overrriden method of
method of superclass
f. Downcasting(Dog to Pug)
i. Must be done manually so that it can never fail
ii. Automatically downcast during method calls
iii. Use conditional check: instanceOf
iv. instanceOf
g. Dynamic binding (Late binding) (runtime polymorphism)
i. Def: decide what method to call)
ii. Occur when a var contains a polymorphic reference
iii. JVM decides what method to call at runtime depending on the type of
obj that variable references
iv. The Object’s type(righthand side) determines which method is called,
not the variable’s type
v. Achieved through dynamic method dispatch (a call to overridden
method is resolved at runtime)
1. Why important?
a. We don’t know the concrete runtime type of an
expression, which is determined during runtime
b. Late binding
h. Static binding(compile-time polymorphism)
i. Occurs at compile time by the compiler
ii. Static, private, final methods are bound at compile time
iii. Static method of super cannot be overridden by subclass
iv. Compile-time polymorphism
1. Call to an overloaded method is resolved at compile time rather
than at runtime: method call is determined by the reference
type of parameter
32. UML DIAGRAMS
a. Purpose
i. Standardized modeling language
ii. Consists of diagrams
iii. To help software developers visualize, construct, and document the
artifacts of a software system
b. Goals:
i. User: ready to use, expressive modeling language to develop and
exchange meaningful models
ii. Independent of programming language and development processes
iii. Support higher development concept such as collaborations,
frameworks, patterns, and components.
c. Type:
i. Structural: static structure(what must be present)
ii. Behavioral( dynamic behavior of the obj in a system: what must
happen)
33. Class diagram
a. Structure diagram
b. What does it do?
c. Benefit:
d. Type of relationship
i. Association: r between two separate classes through their obj
1. Multiplicity: 1-1,1-n,n-1
2. Bidirectional: 2 objs are aware of each other. Straight line
3. Unidirectional: only 1 obj is aware of the other and interacts
with it: line arrow
4. Aggregation
5. reflexive
ii. Inheritance: white arrow starting from sub pointing to super
1. Extends interface: dot line with white arrow
iii. Aggregation: has -a, both can survive independently
1. White diamond arrow for aggregation
2. Black diamond: composition
34. Use-case diagram
a. Can be considered both as a behavior diag( describes behavior of the system),
and structure dia(r between actors and use cases)
b. what does it do?
c. goal
d. benefit
e. component
i. actor: user, org, another app: must produce of consume data
ii. system: sequence of actions and interactions
iii. goal: end result
35. Design patterns
a. Def:
b. Type
36. Iterator DS (behavioral DS)
a. Purpose: way to access elements of a collection object in a sequential manner
without needing to know its underlying representation.
b. Benefits:
c. Why use it?
37. Singleton DS(Creational DS)
a. Purpose: restrict the instantiation of a class to a single instance
b. Benefit:
c. Components: static instance, private constructor, static public method
d. Type:
i. Lazy instantiation: postpone creating new instance until its first use
ii. Eager instantiation: create instance during class loading and use public
method to access the instance
38. Adapter DS (structural)
a. Purpose: allows interface of an existing class to be used as another interface
b. Components: adapter (interface), adaptee(instance of existing class)
39. Factory DS (creational)
a. Purpose: create an obj without exposing its creation logic to the client
b. Used when need to return one of several possible classes that share a common
super class
c. When don’t know ahead of time what class obj is needed
d. Assume that all potential classes extend from the same super class
e. Contain the business logic for creation
f. Benefits: reuse, testing, extensibility, abstraction
40. Decorator DS ( Structural)
a. Purpose: change the behavior of an object dynamically by wrapping the existing
obj in another class that is of the same type
b. Benefits:
i. More flexible: Allows additional functionality to be added at runtime
ii. Easy to add new functionality
iii. Does not need to modify existing code
c. Implementation
i. Abstract classes/interfaces with composition to implement the wrapper
ii. Original is wrapped by decorator classes
41. Façade DS (Structural)
a. Purpose: provide a simplified interface to a large, complex body of code
b. When to use: simple interface to access a complex system
c. Benefits:
i. Library easier to use and understand
ii. Code more readable
iii. Wrapped a poorly designed collection of APIs with a single-well
designed API
42. DS comparison
43. Proxy DS (structural)
a. Purpose: control and manage access to the object the proxy is protecting
b. Can be chained together
c. Proxy provides the same interface to its subject. Adapter: different interface,
decorator: enhanced interface
44. State DS
a. Allow an obj to alter its behavior when its internal state changes
45. Model View Controller
a. Develop user interfaces
b. Components:
i. Model: data and rules that govern access and updates of this data
ii. View: display model data and send button clicks to the controller
iii. Controller: provides model data to view and interprets user actions

Вам также может понравиться