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

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

?? ch14.htm

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

fuNCtion works outside the object-oriented world.

<H3><A NAME="ExampleInitializingProperties">

Example: Initializing Properties</A></H3>

<P>

You now know how to instantiate a new class by using a <TT>new()</TT>

fuNCtion and how to create class properties (the class information)

with undefined values. Let's look at how to give those properties

some real values. You need to start by looking at the <TT>new()</TT>

fuNCtion from Listing 14.1. It's repeated here so you don't need

to flip back to look for it.

<BLOCKQUOTE>

<PRE>

sub new {

        my($class) = shift;

        bless {

            &quot;PART_NUM&quot;    =&gt; undef,

            &quot;QTY_ON_HAND&quot; =&gt; undef

        }, $class;

}

</PRE>

</BLOCKQUOTE>

<P>

The <TT>new()</TT> fuNCtion is a <I>static

</I>method. Static methods are not associated with any specific

object. This makes sense because the <TT>new()</TT>

fuNCtion is designed to create objects. It can't be associated

with an object that doesn't exist yet, can it?

<P>

The first argument to a static method is always the class name.

Perl takes the name of the class from in front of the -&gt; operator

and adds it to the beginning of the parameter array, which is

passed to the <TT>new()</TT> fuNCtion.

<P>

If you want to pass two values into the <TT>new()</TT>

fuNCtion to initialize the class properties, you can modify the

method to look for additional arguments as in the following:

<BLOCKQUOTE>

<PRE>

sub new {

        my($class)   = shift;

        my($partNum) = shift;

        my($qty)     = shift;



        bless {

            &quot;PART_NUM&quot;    =&gt; $partNum,

            &quot;QTY_ON_HAND&quot; =&gt; $qty

        }, $class;

}

</PRE>

</BLOCKQUOTE>

<P>

Each parameter you expect to see gets shifted out of the parameter

array into a scalar variable. Then the scalar variable is used

to initialize the anonymous hash.

<P>

You invoke this updated version of <TT>new()</TT>

by using this line of code:

<BLOCKQUOTE>

<PRE>

$item = Inventory_item-&gt;new(&quot;AW-30&quot;, 1200);

</PRE>

</BLOCKQUOTE>

<P>

While this style of parameter passing is very serviceable, Perl

provides for the use of another technique: passing named parameters.

<H3><A NAME="ExampleUsingNamedParametersinConstructors">

Example: Using Named Parameters in Constructors</A></H3>

<P>

The coNCept of using named parameters has been quickly accepted

in new computer languages. I was first introduced to it while

working with the scripting language for Microsoft Word. Rather

than explain the technique in words, let me show you an example

in code, as shown in Listing 14.2. I think you'll understand the

value of this technique very quickly.

<P>

<IMG SRC="pseudo.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/pseudo.gif" BORDER=1 ALIGN=RIGHT><p>

<BLOCKQUOTE>

<I>Start a definition of the </I><TT><I>Inventory_item</I></TT><I>

class.<BR>

Define the constructor for the class.<BR>

Get the name of the class from the parameter array.<BR>

Assign the rest of the parameters to the </I><TT><I>%params</I></TT><I>

hash.<BR>

Bless the anonymous hash with the class name.<BR>

Use </I><TT><I>%params</I></TT><I>

to initialize the class properties.<BR>

Start the </I><TT><I>main</I></TT><I>

namespace.<BR>

Call the constructor for the </I><TT><I>Inventory_item</I></TT><I>

class.<BR>

Assign the object refereNCe to </I><TT><I>$item</I></TT><I>.

<BR>

Print the two property values to verify that the property initialization

worked.</I>

</BLOCKQUOTE>

<HR>

<BLOCKQUOTE>

<B>Listing 14.2&nbsp;&nbsp;14LST02.PL-Setting Class Properties

Using the Class Constructor<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

package Inventory_item;

    sub new {

        my($class)  = shift;

        my(%params) = @_;



        bless {

            &quot;PART_NUM&quot;    =&gt; $params{&quot;PART_NUM&quot;},

            &quot;QTY_ON_HAND&quot; =&gt; $params{&quot;QTY_ON_HAND&quot;}

            }, $class;

    }



package main;



    $item = Inventory_item-&gt;new(

&quot;PART_NUM&quot;    =&gt; &quot;12A-34&quot;,

&quot;QTY_ON_HAND&quot; =&gt; 34);



    print(&quot;The part number is &quot; . %{$item}-&gt;{'PART_NUM'} . &quot;\n&quot;);

    print(&quot;The quantity is &quot; . %{$item}-&gt;{'QTY_ON_HAND'} . &quot;\n&quot;);

</PRE>

</BLOCKQUOTE>

<HR>

<P>

One key statement to understand is the line in which the <TT>new()</TT>

fuNCtion is called:

<BLOCKQUOTE>

<PRE>

$item = Inventory_item-&gt;new(

&quot;PART_NUM&quot;    =&gt; &quot;12A-34&quot;,

               &quot;QTY_ON_HAND&quot; =&gt; 34);

</PRE>

</BLOCKQUOTE>

<P>

This looks like an associative array is being passed as the parameter

to <TT>new()</TT>, but looks are deceiving

in this case. The <TT>=&gt;</TT> operator

does exactly the same thing as the comma operator. Therefore,

the preceding statement is identical to the following:

<BLOCKQUOTE>

<PRE>

$item = Inventory_item-&gt;new(&quot;PART_NUM&quot;, &quot;12A-34&quot;, &quot;QTY_ON_HAND&quot;, 34);

</PRE>

</BLOCKQUOTE>

<P>

Also, a four-element array is being passed to<TT>

new()</TT>.

<P>

The second line of the <TT>new()</TT>

fuNCtion, <TT>my(%params) = @_;</TT>

does something very interesting. It takes the four-element array

and turns it into a hash with two entries. One entry is for <TT>PART_NUM</TT>,

and the other is for <TT>QTY_ON_HAND</TT>.

<P>

This conversion (array into hash) lets you access the parameters

by name using <TT>%params</TT>. The

initialization of the anonymous hash-inside the <TT>bless()</TT>

fuNCtion-takes advantage of this by using expressions such as

<TT>$params{&quot;PART_NUM&quot;}</TT>.

<P>

I feel that this technique helps to create self-documenting code.

When looking at the script, you always know which property is

being referred to. In addition, you can also use this technique

to partially initialize the anonymous hash. For example,

<BLOCKQUOTE>

<PRE>

$item = Inventory_item-&gt;new(&quot;QTY_ON_HAND&quot; =&gt; 34);

</PRE>

</BLOCKQUOTE>

<P>

gives a value only to the <TT>QTY_ON_HAND</TT>

property; the <TT>PART_NUM</TT> property

will remain undefined. You can use this technique with any type

of fuNCtion, not just constructors.

<H3><A NAME="ExampleInheritaNCePerlStyle">

Example: InheritaNCe, Perl Style</A></H3>

<P>

You already know that inheritaNCe means that properties and methods

of a parent class will be available to child classes. This section

shows you can use inheritaNCe in Perl.

<P>

First, a little diversion. You may not have realized it yet, but

each package can have its own set of variables that won't interfere

with another package's set. So if the variable <TT>$first</TT>

was defined in package A, you could also define <TT>$first</TT>

in package B without a conflict arising. For example,

<BLOCKQUOTE>

<PRE>

package A;

    $first = &quot;package A&quot;;



package B;

    $first = &quot;package B&quot;;



package main;

    print(&quot;$A::first\n&quot;);

    print(&quot;$B::first\n&quot;);

</PRE>

</BLOCKQUOTE>

<P>

displays

<BLOCKQUOTE>

<PRE>

package A

package B

</PRE>

</BLOCKQUOTE>

<P>

Notice that the <TT>::</TT> is being

used as a scope resolution operator in this example. The <TT>-&gt;</TT>

notation will not work; also, it's okay that <TT>-&gt;</TT>

can't be used because we're not really dealing with objects in

this example, just different namespaces.

<P>

You're probably wondering what this diversion has to do with inheritaNCe,

right? Well, inheritaNCe is accomplished by placing the names

of parent classes into a special array called <TT>@ISA</TT>.

The elements of <TT>@ISA</TT> are

searched left to right for any missing methods. In addition, the

<TT>UNIVERSAL</TT> class is invisibly

tacked on to the end of the search list. For example,

<BLOCKQUOTE>

<PRE>

package UNIVERSAL;

    sub AUTOLOAD {

        die(&quot;[Error: Missing FuNCtion] $AUTOLOAD @_\n&quot;);

    }





package A;

    sub foo {

        print(&quot;Inside A::foo\n&quot;);

    }



package B;

    @ISA = (A);



package main;

    B-&gt;foo();

    B-&gt;bar();

</PRE>

</BLOCKQUOTE>

<P>

displays

<BLOCKQUOTE>

<PRE>

Inside A::foo

[Error: Missing FuNCtion] B::bar B

</PRE>

</BLOCKQUOTE>

<P>

Let's start with the nearly empty class <TT>B</TT>.

This class has no properties or methods; it just has a parent:

the <TT>A</TT> class. When Perl executes

<TT>B-&gt;foo()</TT>, the first line

in the main package, it first looks in <TT>B</TT>.

When the <TT>foo()</TT> fuNCtion is

not found, it looks to the <TT>@ISA</TT>

array. The first element in the array is <TT>A</TT>,

so Perl looks at the <TT>A</TT> class.

Because <TT>A</TT> does have a <TT>foo()</TT>

method, that method is executed.

<P>

When a method can't be found by looking at each element of the

<TT>@ISA</TT> array, the <TT>UNIVERSAL</TT>

class is checked. The second line of the main package, <TT>B-&gt;bar()</TT>,

tries to use a fuNCtion that is not defined in either the base

class <TT>B</TT> or the parent class

<TT>A</TT>. Therefore,  as a last-ditch

effort, Perl looks in the <TT>UNIVERSAL</TT>

class. The <TT>bar()</TT> fuNCtion

is not there, but a special fuNCtion called <TT>AUTOLOAD()</TT>

is.

<P>

The <TT>AUTOLOAD()</TT> fuNCtion is

normally used to automatically load undefined fuNCtions. Its normal

use is a little beyond the scope of this book. However, in this

example, I have changed it into an error reporting tool. Instead

of loading undefined fuNCtions, it now causes the script to end

(via the <TT>die()</TT> fuNCtion)

and displays an error message indicating which method is undefined

and which class Perl was looking in. Notice that the message ends

with a newline to prevent Perl from printing the script name and

line number where the script death took place. In this case, the

information would be meaningless because the line number would

be inside the <TT>AUTOLOAD()</TT>

fuNCtion.

<P>

Listing 14.3 shows how to call the constructor of the parent class.

This example shows how to explicitly call the parent's constructor.

In the next section, you learn how to use the <TT>@ISA</TT>

array to generically call methods in the parent classes. However,

because constructors are frequently used to initialize properties,

I feel that they should always be called explicitly, which causes

less confusion when calling constructors from more than one parent.

<P>

This example also shows how to inherit the properties of a parent

class. By calling the parent class constructor fuNCtion, you can

initialize an anonymous hash that can be used by the base class

for adding additional properties.

<P>

<IMG SRC="pseudo.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/pseudo.gif" BORDER=1 ALIGN=RIGHT><p>

<BLOCKQUOTE>

<I>Start a definition of the </I><TT><I>Inventory_item</I></TT><I>

class.<BR>

Define the constructor for the class.<BR>

Get the name of the class from the parameter array.<BR>

Assign the rest of the parameters to the </I><TT><I>%params</I></TT><I>

hash.<BR>

Bless the anonymous hash with the class name.<BR>

Use </I><TT><I>%params</I></TT><I>

to initialize the class properties.<BR>

Start a definition of the </I><TT><I>Pen</I></TT><I>

class.<BR>

Initialize the </I><TT><I>@ISA</I></TT><I>

array to define the parent classes.<BR>

Define the constructor for the class.<BR>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
不卡视频在线看| 国产婷婷色一区二区三区四区| 婷婷久久综合九色综合绿巨人| 亚洲欧美在线高清| 亚洲特级片在线| 亚洲欧美激情小说另类| 亚洲另类在线制服丝袜| 亚洲一区二区三区四区五区中文| 亚洲欧美日韩精品久久久久| 亚洲精品国产一区二区精华液| 亚洲综合久久久| 日韩福利视频网| 国产美女精品人人做人人爽| 成人性生交大片免费看视频在线| 国内成人免费视频| 国产福利一区在线观看| 成人久久久精品乱码一区二区三区| 成人av小说网| 欧美日韩亚洲国产综合| 久久人人爽人人爽| 亚洲欧洲日韩av| 偷拍日韩校园综合在线| 国产一区二区精品久久| 99精品欧美一区二区三区综合在线| 色欧美88888久久久久久影院| 欧美精品在线视频| 欧美激情综合网| 亚洲综合一二三区| 蜜臀91精品一区二区三区| 免费成人小视频| 99国产麻豆精品| 日韩女优毛片在线| 亚洲丝袜制服诱惑| 日韩黄色小视频| 成+人+亚洲+综合天堂| 欧美人体做爰大胆视频| 国产日产欧美一区| 日韩av网站在线观看| 99视频在线精品| 精品99久久久久久| 一区二区不卡在线播放| 国产成人精品影院| 欧美性色黄大片| 日韩一区在线看| 韩国v欧美v日本v亚洲v| 欧美猛男男办公室激情| 最好看的中文字幕久久| 麻豆精品视频在线观看免费 | 欧美aaa在线| 91丨porny丨国产| 国产丝袜欧美中文另类| 日本vs亚洲vs韩国一区三区二区 | 亚洲女同ⅹxx女同tv| 韩国欧美一区二区| 欧美一区二区三区免费大片| 亚洲欧美区自拍先锋| 成人免费高清在线| 日韩视频一区在线观看| 亚洲综合图片区| 高清不卡一区二区在线| 日韩欧美视频一区| 五月天亚洲婷婷| 国产麻豆精品一区二区| 日韩视频永久免费| 日韩国产欧美在线视频| 欧美日韩国产精选| 午夜av一区二区三区| 在线观看一区二区精品视频| 亚洲色欲色欲www| 色呦呦一区二区三区| 最近中文字幕一区二区三区| 成人不卡免费av| 国产精品毛片久久久久久| 国产不卡高清在线观看视频| 欧美精品一区二区高清在线观看| 麻豆一区二区三| 久久久噜噜噜久噜久久综合| 国产乱码字幕精品高清av| 久久久精品影视| eeuss鲁片一区二区三区在线观看 eeuss鲁片一区二区三区在线看 | 色综合久久久久久久久久久| 国产精品夫妻自拍| 色综合天天在线| 亚洲第一福利视频在线| 欧美乱妇15p| 免费观看一级特黄欧美大片| 亚洲精品一区二区三区福利| 国产成人精品综合在线观看 | 欧美激情综合网| 91在线视频网址| 亚洲成av人综合在线观看| 欧美一区二区三区在线电影| 国产在线观看一区二区| 国产精品色噜噜| 欧美视频在线观看一区二区| 男人的天堂久久精品| 久久久影院官网| 色老汉av一区二区三区| 免费久久99精品国产| 国产精品美女久久福利网站 | 日本中文字幕一区| 久久毛片高清国产| 在线观看av一区二区| 精品一区二区在线视频| 中文字幕在线不卡国产视频| 欧美久久久久久久久| 国产成人综合在线| 亚洲国产一区二区三区青草影视| 欧美videofree性高清杂交| 粗大黑人巨茎大战欧美成人| 亚洲成在人线在线播放| 26uuu久久综合| 欧美中文字幕一区二区三区亚洲| 国产呦萝稀缺另类资源| 亚洲精品视频在线观看网站| 精品粉嫩aⅴ一区二区三区四区| 91丨九色丨尤物| 久久草av在线| 亚洲电影一区二区| 国产精品美女久久久久久久久久久| 欧美日韩激情一区二区| av一区二区不卡| 国精品**一区二区三区在线蜜桃| 艳妇臀荡乳欲伦亚洲一区| 欧美经典一区二区三区| 日韩一二三区视频| 欧美日韩久久久| 日本韩国一区二区三区| zzijzzij亚洲日本少妇熟睡| 极品少妇一区二区| 蜜桃av噜噜一区二区三区小说| 亚洲欧洲无码一区二区三区| 久久这里只有精品首页| 日韩精品一区二区三区蜜臀| 欧美男生操女生| 欧美日韩高清不卡| 91行情网站电视在线观看高清版| 成人免费视频国产在线观看| 国产精品小仙女| 国产九色sp调教91| 国产精品99久| 国产精品系列在线观看| 激情另类小说区图片区视频区| 男女性色大片免费观看一区二区| 午夜精品一区二区三区免费视频 | 在线亚洲精品福利网址导航| 波多野结衣在线一区| 国产xxx精品视频大全| 国产精品原创巨作av| 国产一区二区三区电影在线观看 | 亚洲bt欧美bt精品| 亚洲综合成人在线| 亚洲图片欧美视频| 亚洲成人av电影在线| 丝袜亚洲另类欧美| 日韩 欧美一区二区三区| 麻豆免费看一区二区三区| 蜜臀va亚洲va欧美va天堂| 久久99精品国产麻豆婷婷洗澡| 久久精品噜噜噜成人av农村| 精品一区二区在线视频| 风间由美中文字幕在线看视频国产欧美| 久久精品国产77777蜜臀| 国产高清不卡一区| 99久久免费精品高清特色大片| 成人午夜精品一区二区三区| 91免费版pro下载短视频| 在线精品视频免费观看| 日韩一级在线观看| 久久九九久精品国产免费直播| 亚洲国产精品v| 一区二区三区欧美| 另类综合日韩欧美亚洲| 国产成人av电影在线观看| 色网站国产精品| 日韩视频中午一区| 18欧美乱大交hd1984| 一区二区三区91| 激情文学综合网| av在线不卡观看免费观看| 欧美久久一区二区| 国产日韩欧美精品综合| 亚洲午夜激情av| 国产乱淫av一区二区三区| 色综合天天综合网天天狠天天| 在线播放91灌醉迷j高跟美女| 2024国产精品| 亚洲资源中文字幕| 国产成人啪免费观看软件| 色嗨嗨av一区二区三区| 精品国产99国产精品| 一区二区三区四区在线免费观看| 日韩成人午夜电影| 99久久精品情趣| 日韩三级免费观看| 伊人性伊人情综合网| 国产不卡在线一区| 日韩一区和二区| 亚洲国产精品欧美一二99| 成人午夜激情片|