You are on page 1of 15

ClS 304

Cb[ecL ConcepLs and 1ermlnology - 1



ur. SLeven Curl
rofessor, CompuLer lnformauon SysLems
Cal oly omona
1odays 1oplcs
- Cb[ecL ConcepLs and 1ermlnology
- lnherlLance

Cb[ecL ConcepLs
#1: Class

A LemplaLe LhaL denes Lhe meLhods and characLerlsucs Lo be lncluded ln
a parucular Lype of ob[ecL.

SynLax:
class !"#$$%#&'

Lxamples:
class AccounL, CusLomer, uocumenL, Map, 8eservauon

Cb[ecL ConcepLs
#2: lnsLance

AnoLher name for an ob[ecL LhaL belongs Lo a parucular class. When an
appllcauon ls runnlng, ob[ecLs are lnsLanuaLed from a class, and Lhe
ob[ecLs become lnsLances of LhaL class.

SynLax:
new !"#$$%#&'( *

Lxample:
new vehlcle(1oyoLa rlus),

CuLpuL:
1oyoLa rlus represenLs an lnsLance of vehlcle.

Cb[ecL ConcepLs
#3: uML

uML or unled Modellng Language ls a sLandard for deslgnlng and
documenung ob[ecL-orlenLed soware.





Common Lypes of uML dlagrams:
use case dlagram
Class dlagram
lnLeracuon dlagram



Cb[ecL ConcepLs
#4: Lncapsulauon

A Lechnlque ln whlch daLa are packaged LogeLher along wlLh Lhelr
correspondlng procedures. Lncapsulauon (someumes known as daLa
hldlng) shlelds boLh meLhods and aurlbuLes from Lhe ouLslde world.

lour Lypes of vlslblllLy
1. ubllc
2. rlvaLe
3. roLecLed
4. ackage (defaulL)

Cb[ecL ConcepLs
#3: Cb[ecL

An ob[ecL represenLs an lnsLance of a class. lL can be used Lo model an
lndlvldual, unlL, enuLy, elLher real or absLracL, or anyLhlng else LhaL can be
clearly dened.

An ob[ecL, llke a noun, can be a person, place, or Lhlng -- baslcally, any
concepL LhaL ls appllcable Lo Lhe deslgn of Lhe sysLem.



Cb[ecL ConcepLs
#6: MeLhods

A procedure wlLhln an ob[ecL ls called a &'+,-./ MeLhods are Lhlngs LhaL
a class or ob[ecL does and usually conLaln buslness loglc employed ln Lhe
appllcauon. 1hey are slmllar Lo a funcuon ln sLrucLured programmlng
languages.

MeLhods are ldenued by Lhelr name and argumenL llsL known LogeLher
as a $01%#+23'/


Lxample:
vold Clock (uaLe daLe)
vold drawllgure( )


Cb[ecL ConcepLs
#6: Cverloadlng:

Clvlng Lwo or more meLhods Lhe same name buL dlerenL argumenL llsLs
ls called -4'3"-#.0%1/

Lxample:
publlc vold prlnL1oConsole( )
publlc vold prlnL1oConsole(SLrlng separaLor)
publlc vold prlnL1oConsole(SLrlng separaLor, boolean prlnLLlneAer)

uses:
roducL p = new roducL( ),
p.prlnL1oConsole( ),
Cb[ecL ConcepLs
#7: AurlbuLes/CharacLerlsucs vs. MeLhods

AurlbuLes dene daLa, whlle meLhods dene Lhe funcuonallLy.

- AurlbuLes are dened by Lhelr names and Lypes (e.g., 0%+'1'35 6+30%15
7#+').
- MeLhods are dened by wrlung code.
- AurlbuLes and meLhods can boLh be encapsulaLe and hence shlelded by
Lhelr correspondlng ob[ecLs.


Cb[ecL ConcepLs
#8: Pow Lo use Lhe +,0$ keyword

!ava provldes Lhe keyword Lhls Lo refer Lo Lhe currenL ob[ecL. lL ls also
used Lo dlsungulsh lnsLance varlables from local varlables creaLed wlLhln
meLhods or oLher block sLrucLures.

SynLax:
Lhls.varlablename // refers Lo an lnsLance varlable
Lhls (argumenLLlsL) // refers Lo anoLher consLrucLor
Lhls.meLhodname( ) // refers Lo a meLhod ln Lhls class
ob[ecL.meLhod (Lhls) // passes Lhe currenL ob[ecL

Cb[ecL ConcepLs
#9: asslng rlmluve 1ypes vs. 8eference 1ypes

When passlng prlmluves as argumenLs for a meLhod, Lhese Lypes are
always passed by value (or copled). Changes Lo Lhe recelved value have
no lmpacL on Lhe orlglnal values.

Cb[ecLs are always passed by reference, whlch means LhaL a 8-0%+'3 Lo Lhe
ob[ecL ls passed. Changes Lo Lhe recelved value 90"" change Lhe orlglnal
held by Lhe ob[ecL.


Cb[ecL ConcepLs
#10: ConsLrucLors

unless an argumenL ls provlded, !ava wlll use Lhe defaulL consLrucLor
when creaung an ob[ecL. 1hls consLrucLor wlll lnluallze numerlc daLa as
zero and sLrlngs as null.

A few polnLs ...
1. ConsLrucLors never have a reLurn Lype
2. ConsLrucLors always have Lhe same name as Lhelr class
3. Muluple consLrucLors are allowed wlLh addluonal consLrucLors
dlsungulshed by Lhelr $01%#+23'$/


Cuesuons
1ry Lhe revlew exerclses
ln 8lackboard.

You might also like