Please enable JavaScript.
Coggle requires JavaScript to display documents.
Procedural Programming vs. Object-Oriented Programming - Coggle Diagram
Procedural Programming vs. Object-Oriented Programming
Procedural
thinks in terms of what things a program has to do
when specification of the program changes, you have to change the existing code and re-test all
Java OOP
when specification of the program changes, you can test only the changed portion
Steps for efficient design:
Check what is common in all the classes.
Abstract the common feature and put in a superclass.
Inherit all the subclass with feature from superclass.
Override any specific requirement in one of the subclass.
Class
blueprint of an
object
Object
knows things about itself
instance variables
they represent the state of an object
does things
methods
they represent the behavior of an object
takes parameters
values you pass as an arguments to a method:
must match the order and type of the parameters declared by the method
one or more
can be a literal value or a variable of the declared parameter type
Values passed in and out of methods can be implicitly promoted to a larger type or explicitly cast to a smaller type
must declare a return type
tester
where you put the main method where you create and access objects of your new class type
uses the dot operator (.) to access the
methods and variables of the new objects
Variable Types
instance
scope: all through the class except in static methods
declared inside a class, not within a method
class
scope: all through the class
local
scope: within the block it is declared
declared within a method
real
for the type of object you want to use
a java program is nothing more than objects ‘talking’ to other object
Data Types
primitive
two primitives can be compared using the == operator
reference
when == is used for equality check of references it just tells if both reference point to the same Heap Address
Encapsulation
The instance variable should be hidden by the use of
private access modifiers
.
Instance variables can only be accessed using a
getter
or a
setter method
with public access modifiers.
Any place where a particular value can be used, a method call that returns that type can be used.
data hiding (hides the implementation details from users)
Extra-Strength Methods
prep code
a form of pseudocode
instance variable declaration
method declaration
method logic
test code
class or method that tests the real code and validate the process that is working according to the requirements
real code
actual implementation of the class
converting a string to an integer:
Integer.parseInt() method
works only on Strings that represent the ASCII values for digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
for loop
enhanced for loop
for(typeName variable : collection (an array) ) { statements }
regular for loop
for(initialization; boolean test; iteration expression) { statements }
vs. while loop
has only the boolean test; it doesn’t have a built-in initialization or iteration expression
used when number of iteration is unknown and just want to keep going while some condition is true
Java APIs
Java standard edition ships with hundreds of pre-built classes
classes
interfaces
user interfaces
Array List
java.util package
resizable
objects can be added (through add(anObject) method) or removed
we can specify an index using the add(anInt, anObject) method
parameterized types
Using the Library
classes are grouped into
packages
provides name scoping to prevent collisions
provide security because you can restrict the code you write so that only other classes in the same package can access it
extensions
packages that do not come with a standard library
to use a class in the API, you have to know which package the class is in