亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch14.htm

?? prrl 5 programs codes in the book
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
<HTML>

<HEAD>

<TITLE>Chapter 14  -- What Are Objects?</TITLE>



<META>

</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#CE2910">

<H1><FONT SIZE=6 COLOR=#FF0000>Chapter&nbsp;14</FONT></H1>

<H1><FONT SIZE=6 COLOR=#FF0000>What Are Objects?</FONT></H1>

<HR>

<P>

<CENTER><B><FONT SIZE=5>CONTENTS</FONT></B></CENTER>

<UL>

<LI><A HREF="#LearningaboutClasses">

Learning about Classes</A>

<LI><A HREF="#AbstractThinking">

Abstract Thinking</A>

<LI><A HREF="#OverridingMethodswithPolymorphism">

Overriding Methods with Polymorphism</A>

<LI><A HREF="#KeepingCodeandDataTogetherwithENCapsulation">

Keeping Code and Data Together with ENCapsulation</A>

<LI><A HREF="#HowPerlHandlesObjects">

How Perl Handles Objects</A>

<UL>

<LI><A HREF="#ExampleBlesstheHashandPasstheRefereNCe">

Example: Bless the Hash and Pass the RefereNCe</A>

<LI><A HREF="#ExampleInitializingProperties">

Example: Initializing Properties</A>

<LI><A HREF="#ExampleUsingNamedParametersinConstructors">

Example: Using Named Parameters in Constructors</A>

<LI><A HREF="#ExampleInheritaNCePerlStyle">

Example: InheritaNCe, Perl Style</A>

<LI><A HREF="#ExamplePolymorphism">

Example: Polymorphism</A>

<LI><A HREF="#ExampleHowOneClassCanContainAnother">

Example: How One Class Can Contain Another</A>

</UL>

<LI><A HREF="#StaticVersusRegularMethodsandVariables">

Static Versus Regular Methods and Variables</A>

<LI><A HREF="#Summary">

Summary</A>

<LI><A HREF="#ReviewQuestions">

Review Questions</A>

<LI><A HREF="#ReviewExercises">

Review Exercises</A>

</UL>



<HR>

<P>

Actually, &quot;What are objects?&quot; is a silly question because

you already know what an object is. Trust your instiNCts. The

book you are reading is an object. The knife and fork you eat

with are objects. In short, your life is filled with them.

<P>

The question that really needs to be asked is, &quot;What are

classes?&quot; You see, all object-oriented techniques use classes

to do the real work. A <I>class</I> is a combination of variables

and fuNCtions designed to emulate an object. However, when referring

to variables in a class, object-oriented folks use the term <I>properties</I>;

and when referring to fuNCtions in a class, the term <I>method</I>

is used.

<P>

I'm not sure why new terminology was developed for object-oriented

programming. Because the terms are now commonplace in the object-oriented

documentation and products, you need to learn and become comfortable

with them in order to work efficiently.

<P>

In this chapter, you see how to represent objects in Perl using

classes, methods, and properties. In addition, you look at the

definitions of some big words such as <I>abstraction</I>, <I>eNCapsulation</I>,

<I>inheritaNCe</I>, and <I>polymorphism</I>.

<P>

Following are short definitions for these words. The sections

that follow expand on these definitions and show some examples

of their use.

<BLOCKQUOTE>

<B>Abstraction:</B> Information about an object (its properties)

can be accessed in a manner that isolates how data is stored from

how it is accessed and used.

</BLOCKQUOTE>

<BLOCKQUOTE>

<B>ENCapsulation:</B> The information about an object and fuNCtions

that manipulate the information (its methods) are stored together.

</BLOCKQUOTE>

<BLOCKQUOTE>

<B>InheritaNCe:</B> Classes can inherit properties and methods

from one or more parent classes.

</BLOCKQUOTE>

<BLOCKQUOTE>

<B>Polymorphism:</B> A child class can redefine a method already

defined in the parent class.

</BLOCKQUOTE>

<H2><A NAME="LearningaboutClasses"><FONT SIZE=5 COLOR=#FF0000>

Learning about Classes</FONT></A></H2>

<P>

Before looking at specific examples of object-oriented Perl code,

you need to see some generic examples. Looking at generic examples

while learning the &quot;standard&quot; object-oriented terminology

will ensure that you have a firm grasp of the coNCepts. If you

had to learn new Perl coNCepts at the same time as the object

coNCepts, something might be lost because of information overload.

<P>

<I>Classes</I> are used to group and describe object types. Remember

the character classes from <A HREF="ch10.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch10.htm" >Chapter 10</A>, &quot;Regular Expressions&quot;?

A class in the object-oriented world is essentially the same thing.

Let's create some classes for an inventory system for a pen and

peNCil vendor. Start with a pen object. How could you describe

a pen from an inventory point of view?

<P>

Well, the pen probably has a part number, and you need to know

how many of them there are. The color of the pen might also be

important. What about the level of ink in the cartridge-is that

important? Probably not to an inventory system because all the

pens will be new and therefore full.

<P>

The thought process embodied in the previous paragraph is called

<I>modeling</I>. Modeling is the process of deciding what will

go into your objects. In esseNCe, you create a model of the world

out of objects.<BR>

<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD><B>Tip</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

The terms <TT><I>object</I></TT> and <TT><I>class</I></TT> are pretty interchangeable. Except that a class might be considered an object described in computer language, whereas an object is just an object.

</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<P>

Objects are somewhat situationally dependent. The description

of an object, and the class, depends on what needs to be done.

If you were attempting to design a school course scheduling program,

your objects would be very different than if you were designing

a statistics program.

<P>

Now back to the inventory system. You were reading about pens

and how they had colors and other identifying features. In object

talk, these features are called <I>properties</I>. Figure 14.1

shows how the pen class looks at this stage of the discussion.

<P>

<A HREF="f14-1.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/f14-1.gif"><B>Figure 14.1 : </B><I>The Pen Class and its properties</I>.</A>

<P>

Now that you have a class, it's time to generalize. Some people

generalize first. I like to look at the details first and then

extract the common information. Of course, usually you'd need

several classes before any common features will appear. But because

I've already thought this example through, you can cheat a little.

<P>

It's pretty obvious that all inventory items will need a part

number and that each will have its own quantity-on-hand value.

Therefore, you can create a more general class than Pen. Let's

call it <TT>Inventory_item</TT>. Figure

14.2 shows this new class.

<P>

<A HREF="f14-2.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/f14-2.gif"><B>Figure 14.2 : </B><I>The Inventory_item class and its properties</I>.</A>

<P>

Because some of <TT>Pen's</TT> properties

are now also in <TT>Inventory_item</TT>,

you need some mechanism or technique to avoid repetition of information.

This is done by deriving the <TT>Pen</TT>

class from <TT>Inventory_item</TT>.

In other words, <TT>Inventory_item</TT>

becomes the <I>parent</I> of <TT>Pen</TT>.

Figure 14.3 shows how the two classes are now related.

<P>

<A HREF="f14-3.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/f14-3.gif"><B>Figure 14.3 : </B><I>The relationship between Inventory_item

and Pen</I>.</A>

<P>

You may not have noticed, but you have just used the coNCept of

<I>inheritaNCe</I>. The <TT>Pen</TT>

class inherits two of its properties from the <TT>Inventory_item</TT>

class. InheritaNCe is really no more complicated than that. The

child class has the properties of itself plus whatever the parent

class has.

<P>

You haven't seen methods or fuNCtions used in classes yet. This

was deliberate. Methods are inherited in the same way that data

is. However, there are a couple of tricky aspects of using methods

that are better left for later. Perhaps even until you start looking

at Perl code.<BR>

<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD><B>Note</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

Even though you won't read about methods at this point in the chapter, there is something important that you need to know about inheritaNCe and methods. First, methods are inherited just like properties. Second, using inherited methods helps to create 
your program more quickly because you are using fuNCtionality that is already working. Therefore-at least in theory-your programs should be easier to create.</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<H2><A NAME="AbstractThinking"><FONT SIZE=5 COLOR=#FF0000>

Abstract Thinking</FONT></A></H2>

<P>

Earlier, I mentioned the term <I>abstraction</I>. Let's examine

the idea a little further. In order to do this, you need a working

definition of the term <I>model</I>. How about, &quot;A model

is an approximation of something.&quot; If you build a model car,

some of the items in the original car will be missing, such as

spark plugs, for example. If you build a model house, you wouldn't

iNClude the plumbing. Thus, the models that you build are somewhat

abstract; the details don't matter, just the form.

<P>

Abstraction in object-oriented programming works in the same way.

As the programmer, you present the model of your objects to other

programmers in the form of an <I>interface</I>. Actually, the

interface is just some documentation that tells others how to

interact with any of your classes. However, nobody needs to know

what your classes really do. It is enough to say that the file

object stores the file name and size and presents the information

in English. Whether the internal format of the information is

compressed, Russian, or stored in memory or on the hard disk is

immaterial to the user of your classes.

<P>

I recommend that as you design an object or class, you occasionally

distaNCe yourself from the work. Try to view the resulting system

through the eyes of another to check for iNConsisteNCies and relationships

that aren't needed.

<P>

You've learned about abstraction in abstract terms so far. Now

let's use the <TT>Pen</TT> class that

you created earlier to see a coNCrete example of abstraction.

The <TT>Pen</TT> class had only one

property of its own, the ink color (the rest were inherited).

For the sake of argument, the ink color can be <TT>&quot;blue,&quot;</TT>

<TT>&quot;black,&quot;</TT> or <TT>&quot;red.&quot;</TT>

When a <TT>Pen</TT> object is created

(the mechanism of creation is unimportant at the moment), a specific

color is assigned to it. Use <TT>&quot;blue&quot;</TT>

for the moment. Here is a line of code to create the object:

<BLOCKQUOTE>

<PRE>

$pen = Pen-&gt;new(&quot;blue&quot;);

</PRE>

</BLOCKQUOTE>

<P>

Now the <TT>Pen</TT> object has been

created. Do you care if the internal format of the ink color is

the string <TT>&quot;blue&quot;</TT>

or the number 1? What if, because you expect to use thousands

of objects, the internal format changes from a string to a number

to save computer memory? As long as the interface does not change,

the program that uses the class does not need to change.

<P>

By keeping the external interface of the class fixed, an abstraction

is being used. This reduces the amount of time spent retrofitting

programs each time a change is made to a class the program is

using.

<H2><A NAME="OverridingMethodswithPolymorphism"><FONT SIZE=5 COLOR=#FF0000>

Overriding Methods with Polymorphism</FONT></A></H2>

<P>

<I>Polymorphism</I> is just a little more complicated than inheritaNCe

because it involves methods. Earlier, I said you might not learn

about methods before you look at a real object-oriented Perl program,

but I changed my mind. Let's make up some methods that belong

in an inventory program. How about a method to print the properties

for debugging purposes or a method to change the quantity-on-hand

amount? Figure 14.4 shows the <TT>Inventory_item</TT>

class with these two fuNCtions.

<P>

<A HREF="f14-4.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/f14-4.gif"><B>Figure 14.4 : </B><I>The Inventory_item class with methods</I>.</A>

<P>

This new fuNCtion is automatically inherited by the <TT>PEN</TT>

class. However, you will run into a problem because the <TT>printProperties()</TT>

fuNCtion won't print the ink color. You have three choices:

<UL>

<LI>Change the fuNCtion in the <TT>Inventory_item</TT>

class-This is a bad choice because the generic inventory item

should not know any unique information about inventory objects-just

general or common information.

<LI>Create a new fuNCtion in the <TT>Pen</TT>

class called <TT>printPenProperties()-</TT>This

is another bad choice. By solving the problem this way, every

class will soon have its own print fuNCtions, and keeping track

of the fuNCtion names would be a nightmare.

<LI>Create a new fuNCtion in the <TT>Pen</TT>

class called <TT>printProperties()</TT>

to <I>override</I> the definition from <TT>Inventory_item</TT>.

This is a good solution. In fact, this is the way that polymorphism

works.

</UL>

<P>

Perl's take on polymorphism is that if you call a method in your

program, either the current class or a parent class should have

defined that method. If the current class has not defined the

method, Perl looks in the parent class. If the method is still

not found, Perl continues to search the class <I>hierarchy</I>.

<P>

I can hear you groaning at this point-another object-oriented

word! Yes, unfortunately. But at least this one uses the normal,

everyday definition of the word. A <I>hierarchy</I> is an organized

tree of information. In our examples so far, you have a two-level

hierarchy. It's possible to have class hierarchies many levels

deep. In fact, it's quite common. Figure 14.5 shows a class hierarchy

with more than one level.

<P>

<A HREF="f14-5.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/f14-5.gif"><B>Figure 14.5 : </B><I>A class hierarchy with many levels</I>.</A>

<P>

It's probably worth mentioning that some classes contain only

information and not methods. As far as I know, however, there

is no special terminology to reflect this. These information-only

classes may serve as adjuNCt or helper classes.

<H2><A NAME="KeepingCodeandDataTogetherwithENCapsulation"><FONT SIZE=5 COLOR=#FF0000>

Keeping Code and Data Together with ENCapsulation</FONT></A></H2>

<P>

There's not much that I need to say about eNCapsulation. Keeping

the methods in the same place as the information they affect seems

like common sense. It wasn't done using earlier languages mostly

because the programming tools were not available. The extra work

required to manually perform eNCapsulation outweighed the benefits

that would be gained.

<P>

One big advantage of eNCapsulation is that it makes using information

for unintended purposes more difficult, and this reduces logic

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美精品一区二区三区在线| 成人h动漫精品一区二区| 国产欧美日韩在线视频| 91国偷自产一区二区三区观看 | 91久久久免费一区二区| 日本欧美一区二区在线观看| 中文字幕在线一区| 日韩欧美区一区二| 欧美色中文字幕| 成人三级伦理片| 久久精品国产亚洲高清剧情介绍| 亚洲欧美色综合| 国产清纯在线一区二区www| 欧美美女直播网站| 色播五月激情综合网| 国产麻豆欧美日韩一区| 奇米一区二区三区| 亚洲愉拍自拍另类高清精品| 国产精品无人区| 久久中文字幕电影| 3d动漫精品啪啪| 欧美性大战久久久久久久| 99v久久综合狠狠综合久久| 国产主播一区二区三区| 蜜臀精品一区二区三区在线观看 | 国产精品888| 久久精品国产**网站演员| 午夜精品123| 亚洲一区二区欧美| 亚洲色图在线看| 国产精品麻豆99久久久久久| 久久久不卡网国产精品一区| 欧美电影免费观看高清完整版在| 欧美一区二区三区性视频| 欧美日韩高清一区| 欧美色倩网站大全免费| 在线一区二区观看| 欧洲精品一区二区| 色94色欧美sute亚洲线路二 | 亚洲成av人**亚洲成av**| 亚洲男女毛片无遮挡| 亚洲人成影院在线观看| 亚洲三级在线免费观看| 亚洲欧美一区二区不卡| 国产精品久久久久久久久图文区| 国产色综合一区| 国产精品美女久久久久久久久久久| 欧美精品一区二区在线播放| 国产日韩精品一区二区三区在线| 久久蜜桃av一区精品变态类天堂| 国产亚洲欧美日韩日本| 国产精品剧情在线亚洲| 自拍偷拍欧美精品| 亚洲成年人影院| 蜜桃久久久久久久| 国产精品一区在线观看你懂的| 国产精品一区免费视频| 成人网在线播放| 色婷婷久久久综合中文字幕| 欧美偷拍一区二区| 日韩欧美一级片| 久久精品免费在线观看| 中文字幕在线不卡国产视频| 一区二区三区中文字幕| 天天爽夜夜爽夜夜爽精品视频| 麻豆精品国产传媒mv男同| 国产精品亚洲第一| 91免费国产在线| 欧美日韩高清在线播放| wwwwxxxxx欧美| 中文字幕一区三区| 午夜成人在线视频| 国产精品一区二区在线观看网站| 成人免费视频caoporn| 欧美做爰猛烈大尺度电影无法无天| 在线不卡a资源高清| 久久蜜桃香蕉精品一区二区三区| 亚洲日本va午夜在线影院| 亚洲第一二三四区| 国产一区二区三区在线观看精品 | 欧美中文字幕一区二区三区 | 亚洲影院久久精品| 麻豆久久久久久久| 成人精品免费视频| 欧美精品三级日韩久久| 国产亚洲一本大道中文在线| 亚洲精品免费看| 狠狠色综合日日| 色哟哟一区二区| 欧美精品一区男女天堂| 亚洲一区免费在线观看| 国产一级精品在线| 欧美日韩一区三区| 国产精品拍天天在线| 日一区二区三区| 91在线无精精品入口| 日韩精品一区二区在线观看| 一区二区在线看| 国产剧情在线观看一区二区| 欧美日韩一级二级三级| 欧美激情一区三区| 免费xxxx性欧美18vr| 91国产丝袜在线播放| 国产亲近乱来精品视频| 欧美a一区二区| 在线看国产一区| 欧美激情一区二区三区不卡| 日本特黄久久久高潮| 色素色在线综合| 国产精品久久久爽爽爽麻豆色哟哟 | 丁香婷婷综合色啪| 精品久久久三级丝袜| 日韩中文字幕1| 在线一区二区视频| 亚洲人xxxx| 成人蜜臀av电影| 国产蜜臀av在线一区二区三区| 蜜臀久久99精品久久久画质超高清 | 日韩av在线播放中文字幕| 在线亚洲欧美专区二区| 亚洲欧洲成人av每日更新| 国产99久久久精品| 久久在线观看免费| 免费成人在线视频观看| 色综合久久中文字幕综合网 | 亚洲夂夂婷婷色拍ww47| 成人黄色软件下载| 久久一区二区三区四区| 亚洲欧洲日产国产综合网| 成人听书哪个软件好| 日韩欧美电影在线| 日韩高清一区在线| 欧洲人成人精品| 亚洲成人在线网站| 色婷婷久久99综合精品jk白丝| 久久日韩精品一区二区五区| 欧美a一区二区| 欧美蜜桃一区二区三区| 国产精品视频一二三| 欧美aaaaa成人免费观看视频| 欧美三级日韩三级国产三级| 日韩毛片视频在线看| 国产91丝袜在线观看| 国产精品沙发午睡系列990531| 狠狠色综合色综合网络| 日韩免费高清av| 麻豆国产精品官网| 欧美人体做爰大胆视频| 蜜臀精品一区二区三区在线观看 | 粉嫩av亚洲一区二区图片| 精品久久久久久久久久久久久久久久久 | 国产精品美女久久久久久久 | 欧美另类z0zxhd电影| 亚洲国产精品久久一线不卡| 777久久久精品| 午夜精品福利视频网站| 欧美电影一区二区三区| 日韩中文字幕91| 国产人伦精品一区二区| 成人午夜视频在线观看| 国产精品免费久久| av在线播放一区二区三区| 中文字幕精品三区| 欧美性猛片xxxx免费看久爱| 亚洲国产成人av好男人在线观看| 欧美日韩一卡二卡三卡| 秋霞影院一区二区| 亚洲国产精品国自产拍av| 成人午夜短视频| 亚洲美女在线一区| 欧美日韩一区不卡| 国产精品77777竹菊影视小说| 国产精品区一区二区三区| 91欧美激情一区二区三区成人| 亚洲综合久久久| 欧美一区二区三区四区久久| 久久99精品国产.久久久久久| 久久午夜电影网| 99天天综合性| 亚洲精品成人少妇| 久久新电视剧免费观看| 91美女在线视频| 日本亚洲电影天堂| 精品国产三级电影在线观看| 97国产精品videossex| 午夜婷婷国产麻豆精品| 精品伦理精品一区| 成人美女视频在线看| 麻豆久久久久久久| 国产精品福利影院| 在线不卡a资源高清| 国产v综合v亚洲欧| 天天综合网 天天综合色| 国产精品久久久一本精品| 欧美另类一区二区三区| 成人网页在线观看| 国产伦精品一区二区三区视频青涩 | 色香色香欲天天天影视综合网| 日本中文字幕一区二区有限公司| 国产亚洲综合av|