Encapsulation
Në shqip: Kapsulim
ShpjegimiSQ
Kapsulimi do të thotë t'i fshehësh të dhënat e brendshme të një objekti dhe t'i lejosh të tjerët t'i ndryshojnë vetëm përmes metodave të caktuara. Kështu askush s'mund ta prishë objektin aksidentalisht.
EnglishEN
Encapsulation means hiding an object's internal data and letting others change it only through specific methods. That way nobody can break the object by accident.
Si ta mendosh
Si bankomati: s'i sheh paratë brenda dhe s'i prek dot direkt — mund t'i marrësh vetëm përmes butonave dhe PIN-it.
Lexoje në anglisht
Like a cash machine: you can't see the money inside or touch it directly — you can only take it out through the buttons and your PIN.
Shembull kodipython
class Llogari:
def __init__(self): self.__shuma = 0 # e fshehur
def depozito(self, x):
if x > 0: self.__shuma += x # vetëm përmes metodës