Quick Review Questions
Q1. Which statement best describes the relationship
between an object and a class in object-oriented
programming?
A) A class is an instance of an object, providing the
actual values for data and behaviors.
B) An object is an instance of a class, combining data
and behavior that acts on that data.
C) An object and a class are interchangeable terms
that mean the same thing.
D) A class combines data with behavior that acts on
that data, while an object is a blueprint for
creating classes.
Quick Review Questions
Q2. What is the primary purpose of encapsulation in
object-oriented programming?
A) To ensure that an object can inherit properties
from multiple superclasses simultaneously.
B) To allow objects to change their type at runtime to
any subclass type.
C) To protect some components of an object from
external access, making them private.
D) To specify method signatures without implementing
them, enabling polymorphism.
Quick Review Questions
Q3. Which of the following best demonstrates the
concept of polymorphism in object-oriented
programming?
A) A class that hides its implementation details from
other classes, only exposing an interface.
B) A class that extends another class, adding new
fields and methods to it.
C) An object that can be used interchangeably with its
sub-objects, allowing for different behaviors
through the same piece of code.
D) A set of unrelated classes that implement the same
method signatures defined in an interface.
Quick Review Questions
Q4. Which of the following best describes the initial
step in the software development process before
moving on to object-oriented design?
A) Directly coding the software based on a basic idea
of what the system should do.
B) Creating a user interface prototype to determine
the final appearance of the application.
C) Documenting the desired functionality of the system
in a way that is independent of how it will be
implemented.
D) Designing a detailed data model to outline how data
will be managed within the application.
Quick Review Questions
Q5. Which of the following activities is crucial for
understanding the problem domain and user interactions
with the system, but does not directly involve coding?
A) Developing a conceptual model that captures the main
concepts and relationships relevant to the problem
domain.
B) Implementing the first version of the software to test
its performance and user experience.
C) Refactoring the codebase to improve software design and
maintainability.
D) Optimizing database queries to enhance the system's
data retrieval speed.
Inheritance syntax
public class name extends superclass {
• Example:
public class Lawyer extends Employee {
...
}
• By extending Employee, each Lawyer object now:
• receives a copy of each method from Employee automatically
• can be treated as an Employee by client code
• Lawyer can also replace ("override") behavior from Employee.
Inheritance syntax
public class name extends superclass {
• Example:
public class Lawyer extends Employee {
...
}
• By extending Employee, each Lawyer object now:
• receives a copy of each method from Employee automatically
• can be treated as an Employee by client code
• Lawyer can also replace ("override") behavior from Employee.
The super keyword
• A subclass can call its parent's method/constructor:
[Link](parameters) // method
super(parameters); // constructor
public class Lawyer extends Employee {
public Lawyer(String name) {
super(name);
}
// give Lawyers a $5K raise (better)
public double getSalary() {
double baseSalary = [Link]();
return baseSalary + 5000.00;
}
}
CIS 280 Software Specification & Design
Object Paradigm
9
Basic Concepts
• Abstraction
• Encapsulation / Information Hiding
• Modularity
Abstraction
Abstraction
• Separating properties of an entity…
• …which are relevant…
• …in the context of the problem domain…
• Domain is an area of expertise describing a group or a class of problems
• ... from other properties of the entity.
Abstraction
• Separating properties of an entity…
• …which are relevant…
• …in the context of the problem domain…
• Domain is an area of expertise describing a group or a class of problems
• ...from other properties of the entity.
• Abstraction optimizes the information needed to represent an entity,
in attempt to solve a specific problem
Abstraction
• Separating properties of an entity…
• …which are relevant…
• …in the context of the problem domain…
• Domain is an area of expertise describing a group or a class of problems
• ...from other properties of the entity.
• Abstraction optimizes the information needed to represent an entity,
in attempt to solve a specific problem
• Abstraction represents a view of the entity consistent with the needs
of the domain
Abstraction example
• You’ve been hired to design a banking webpage!
• Your underlings provide you with the following information
about potential customers:
Abstraction example
• You’ve been hired to design a banking webpage!
• Your underlings provide you with the following information
about potential customers:
• You fire them and say, “I need more information than that for this
bank’s website!”
• You then hire some minions to come up with six additional pieces
of information… what do you think they come up with?
Abstraction example
• You’ve been hired to design a banking webpage!
• My domain expert came back with the following information
about potential customers:
Abstraction example
• You’ve been hired to design a banking webpage!
• My domain expert came back with the following information
about potential customers:
• Separating properties of an entity…
• …which are relevant…
• …in the context of the problem domain…
• Domain is an area of expertise describing a
group or a class of problems
• ...from other properties of the entity.
Abstraction example
• After firing everyone, you are now ready to design the banking webpage!
Abstraction example
• After firing everyone, you are now ready to design the banking webpage!
• But the idea of abstraction is that you can use these properties to solve
completely different problems…
Abstraction example
• After firing everyone, you are now ready to design the banking webpage!
• But the idea of abstraction is that you can use these properties to solve
completely different problems…
Abstraction…
• Abstraction is a necessary condition of any problem-solving process.
• Abstraction identifies "the sameness" among entities in terms of
structure, operations, behavior.
Abstraction…
• Abstraction is a necessary condition of any problem-solving process.
• Abstraction identifies "the sameness" among entities in terms of
structure, operations, behavior.
Abstraction…
Abstraction…
Abstraction…
Abstraction…
Abstraction
• Separating properties of an entity (which are relevant in the context of the problem
domain) from other properties of the entity
• Abstraction optimizes the information needed to represent an entity in attempt to
solve a specific problem
• Abstraction represents a view of the entity consistent with the needs of the domain
Abstraction…
• Abstraction is a necessary condition of any problem-solving process.
• Abstraction identifies " the sameness " among entities in terms of
structure, operations, behavior.
Abstraction…
• Abstraction is a necessary condition of any problem-solving process.
• Abstraction identifies " the sameness " among entities in terms of
structure, operations, behavior.
• Lack of abstraction would result in: total diversification, total chaos (of
thoughts), insanity.
Encapsulation • Encapsulation is a mechanism of
wrapping the data (variables) and
code acting on the data (methods)
together as a single unit.
Encapsulation • Encapsulation is a mechanism of
wrapping the data (variables) and
code acting on the data (methods)
together as a single unit.
Encapsulation • Encapsulation is a mechanism of
wrapping the data (variables) and
code acting on the data (methods)
together as a single unit.
• In encapsulation, the variables of a
class will be hidden from other
classes, and can be accessed only
through the methods of their
current class.
Encapsulation • Encapsulation is a mechanism of
wrapping the data (variables) and
code acting on the data (methods)
together as a single unit.
• In encapsulation, the variables of a
class will be hidden from other
classes, and can be accessed only
through the methods of their
current class.
• Encapsulation should be enforced
by entities themselves rather than
the policies in the environment in
which the entities operate.
class Account{
int account_number;
int account_balance;
public void show_data( ){
// code to show data
}
public void deposit(int a ){
// code to deposit
}
}
class Account{ class badGuy{
int account_number; Account a = new Account();
int account_balance; a.account_balance = -100;
public void show_data( ){ }
// code to show data
}
public void deposit(int a ){
// code to deposit
}
}
class Account{ class badGuy{
private int account_number; Account a = new Account();
private int account_balance; a.account_balance = -100;
public void show_data( ){ }
// code to show data
}
public void deposit(int a ){
// code to deposit
}
}
class Account{ class badGuy{
private int account_number; Account a = new Account();
private int account_balance; a.account_balance = -100;
public void show_data( ){ [Link](-100);
// code to show data }
}
public void deposit(int a ){
// code to deposit
}
}
class Account{ class badGuy{
private int account_number; Account a = new Account();
private int account_balance; a.account_balance = -100;
public void show_data( ){ [Link](-100);
// code to show data }
}
public void deposit(int a ){
if (a<0) {
// call the police
}
else {
account_balance = account_balance+a;
}
}
}
class Account{ class badGuy{
private int account_number; Account a = new Account();
private int account_balance; a.account_balance = -100;
public void show_data( ){ [Link](-100);
// code to show data }
}
public void deposit(int a ){
if (a<0) {
// call the police
}
else {
account_balance = account_balance+a;
}
}
}
class Account{ class badGuy{
private int account_number; Account a = new Account();
private int account_balance; a.account_balance = -100;
public void show_data( ){ [Link](-100);
// code to show data }
}
public void deposit(int a ){
if (a<0) {
// call the police
}
else {
account_balance = account_balance+a;
}
}
}
Abstraction: is outlined by the top left and top right images of the cat. The surgeon and the old lady designed (or
visualized) the animal differently. In the same way, you would put different features in the Cat class, depending upon
the need of the application. Every cat has a liver, bladder, heart and lung, but if you need your cat to 'purr' only, you
will abstract your application's cat to the design on top-left rather than the top-right.
Abstraction: is outlined by the top left and top right images of the cat. The surgeon and the old lady designed (or
visualized) the animal differently. In the same way, you would put different features in the Cat class, depending upon
the need of the application. Every cat has a liver, bladder, heart and lung, but if you need your cat to 'purr' only, you
will abstract your application's cat to the design on top-left rather than the top-right.
Encapsulation: is outlined by the cat standing on the table. That's what everyone outside the cat should see the
cat as. They need not worry whether the actual implementation of the cat is the top-left one or the top-right one or
even a combination of both.
Modularity
• Modules are defined as highly cohesive parts of the system.
• Modules are loosely coupled with other modules.
• Modules interact with other modules through their interfaces.
Modularity