C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet50/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   46   47   48   49   50   51   52   53   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Encapsulation

Encapsulation

 is a programming mechanism that binds together code and the data it 

manipulates, and that keeps both safe from outside interference and misuse. In an object-

oriented language, code and data can be bound together in such a way that a self-contained 



black box 

is created. Within the box are all necessary data and code. When code and data are 

linked together in this fashion, an 

object

 is created. In other words, an object is the device 

that supports encapsulation.

Within an object, the code, data, or both may be 



private

 to that object or 



public.

 Private code 

or data is known to and accessible by only another part of the object. That is, private code or 

data cannot be accessed by a piece of the program that exists outside the object. When code 

or data is public, other parts of your program can access it even though it is defined within 

an object. Typically, the public parts of an object are used to provide a controlled interface to 

the private elements.

C#’s basic unit of encapsulation is the 



class.

 A class defines the form of an object. It specifies 

both the data and the code that will operate on that data. C# uses a class specification to 

construct 



objects.

 Objects are instances of a class. Thus, a class is essentially a set of plans 

that specify how to build an object.

Collectively, the code and data that constitute a class are called its 



members

. The data 

defined by the class is referred to as 

fields

. The terms 



member variables

 and


 instance variables 

also are used. The code that operates on that data is contained within 



function members, 

of

which the most common is the 



method.

 Method is C#’s term for a subroutine. (Other 

function members include properties, events, and constructors.) Thus, the methods of a 

class contain code that acts on the fields defined by that class.



Polymorphism

Polymorphism

 (from Greek, meaning “many forms”) is the quality that allows one interface 

to access a general class of actions. A simple example of polymorphism is found in the 

steering wheel of an automobile. The steering wheel (the interface) is the same no matter 

what type of actual steering mechanism is used. That is, the steering wheel works the same 

whether your car has manual steering, power steering, or rack-and-pinion steering. Thus, 

turning the steering wheel left causes the car to go left no matter what type of steering is 

used. The benefit of the uniform interface is, of course, that once you know how to operate 

the steering wheel, you can drive any type of car.

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   46   47   48   49   50   51   52   53   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish