OOP Classes Objects
OOP Classes Objects
OOP ADVANTAGES methods private. As there are some changes in the code,
you can increase the access to “protected” as needed, but
don't use public.
▪ Single Responsibility Principle: This is another best
practice for OOP concepts in Java. This principle says that a
class should always have only one functionality. That way,
we can call it or extend it on its own whenever new uses
arise without providing coupling between different
functionalities.
▪ Open Closed Design: We should try to make all the
methods and classes Closed for any modification but open
for an extension. That way, the tested code can remain
static, but we can modify it to perform new tasks as
required.
OOP MAIN
ASPECTS
Object
Classes are the core of the OOP where objects are created from classes.
Real world objects can be represented using classes then many objects can be created of a
particular class.
model
Attributes
color
year
start
Methods stop
beep
Methods
20
Prepared by: Ms. Dania Alsaid, Ms. Hana Alrasheed
Prepared by: Ms. Dania Alsaid, Ms. Hana Alrasheed 21
22
24
Prepared by: Ms. Dania Alsaid, Ms. Hana Alrasheed
Each Object has its own
copy of the class’s
attributes and methods.
Main Class
Car Class
Prepared by: Ms. Dania Alsaid, Ms. Hana Alrasheed
27
An object Class
name Constructor
New
keyword
A Class you want
to create an object
from it 28
Prepared by: Ms. Dania Alsaid, Ms. Hana Alrasheed
Three objects from
Car Class are created
Each object is
an independent
instance from the
Prepared by: Ms. Dania Alsaid, Ms. Hana Alrasheed 29
others
▪ Each object has its own version of
attributes
Retrieve Attribute:
ObjectName.AttributeName