Академический Документы
Профессиональный Документы
Культура Документы
Class
A blueprint that defines the attributes and methods
Object
An instance of a Class
Abstraction
Hide certain details and show only essential details
Encapsulation
Binding data and methods together
Inheritance
Inherit the features of the superclass
Polymorphism
One name having many forms
2
OOP
Abstraction means ignoring irrelevant features, properties, or functions and emphasizing the relevant ones...
Relevant to what?
... relevant to the given project (with an eye to future reuse in similar projects).
Data Abstraction Programming languages define constructs to simplify the way information is presented to the programmer. Functional Abstraction Programming languages have constructs that gift wrap very complex and low level instructions into instructions that are much more readable. Object Abstraction OOP languages take the concept even further and abstract programming constructs as objects.
Abstraction
Hide certain details and show only essential details public abstract class Shape { String color; public abstract double getArea(); } public interface Shape { String static final String color = BLACK; public abstract double getArea(); }
Inheritance
The
The
As
That
Inheritance in Java
Inheritance is declared using the "extends" keyword If inheritance is not defined, the class extends a class called Object
public class Person { private String name; private Date dob; [...]
public class Employee extends Person { private int employeID; private int salary; private Date startDate; [...]
(a) (b)
Lecture 13
obj.doIt();
This line of code might execute different methods at different times if the object that obj points to changes
Polymorphic references are resolved at run time; this is called dynamic binding
Careful use of polymorphic references can lead to elegant, robust software designs Polymorphism can be accomplished using inheritance or using interfaces
public class Shape { public void display() { System.out.println(In Shape); } } public class Square extends Shape { public void display() { System.out.println(In Square); } }
s4
square
S3 s2 s1
11
shape
One
of the features of object oriented languages Hide the data of an object (variable) Group operations and data together into a new data type Usually easier to use something than understand exactly how it works
CS 314
12