lecture7(process,cause-effect,example)
- 格式:ppt
- 大小:141.00 KB
- 文档页数:17
内容提要★结构型设计模式小结包装型模式群设计模式实例分析Structural Patterns结构模式描述如何将类或者对象结合在一起形成更大的结构。
类的结构模式:类的结构模式使用继承把类、接口等组合在一起,以形成更大的结构。
当一个类从父类继承并实现某接口时,这个新的类就把父类的结构和接口的结构组合起来。
类的结构模式是静态的。
对象的结构模式:对象的结构模式描述了怎样把各种不同类型的对象组合在一起,以实现新功能的方法。
可以在运行时刻改变对象组合关系,对象的结构模式是动态的。
结构模式主要有:Adapter 适配器模式Bridge 桥接模式Composite组合模式Decorator 装饰模式Facade 门面模式Flyweight享元模式Proxy 代理模式1 AdapterAliases:WrapperIntent将一个类的接口转换成客户希望的另外一个接口。
Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作Motivation有时为复用而设计的工具箱类不能够被复用的原因仅仅是因为它的接口与专业应用领域所需要的接口不匹配图示:1. 对象Adapter:Adapter与Adaptee是委派关系图示:2. 类Adapter:Adapter与Adaptee是继承关系Adapter 模式的关键特征Adapter 模式的关键特征用一个满足现有接口需求的新类包含已有类,调用已有类的方法实现新类中的方法实现Adapter 模式使得先前存在的对象可以匹配新的类型,而不受该对象原有接口的限制效果Adapter 对Adaptee 进行适配,使其满足Adapter’s Target 的要求。
这是的用户可以实际使用Adaptee ,就好像它是一种Target 一样。
参与者和协作者Adapter 面向所需的接口提供一个包装器解某系统拥有合适的数据和行为,但接口并不合要求。
问题将一个你难以控制(如无法修改其内部代码)的对象匹配到特定的接口上意图2 BridgeAliases:Handle/BodyIntent将抽象部分与它的实现部分分离,使它们都可以独立地变化Motivation要做到“抽象(接口)与实现分离”,最常用的办法是定义一个抽象类,然后在子类中提供实现。
Producer Theory1Technology1.Production is a process of transforming inputs into outputs.Thefundamental problem…rms must contend with in this process is the technological feasibility.The state of technology determines and restricts what is possible in combining inputs to produce out-put.2.We…rst concentrate on the case in which the…rm produces onlyone output.The case of multiple outputs will be dealt with later.When there is only one output,we will use q2R+to denote the …rm’s output and x2R n+to denote the…rm’s inputs.3.We de…ne the production function as:q=f(x):The production function captures the technology of production.It tells us how much input x is needed to produce a a…xed amount of output q.4.Assumption3.1.The production f:R n+!R+,is continuous,strictly increasing,and strictly quasiconcave on R n+,and f(0)=0.5.The marginal product of x i,MP i=@f @x i;tell us how many extra units of output an extra unit of x i produces. Unlike marginal utility in consumer theory,marginal product is objective and measurable.6.The strict quasiconcavity assumption means that any convex com-bination of two input vectors can produce at least as much output as one of the original two.This would be the case if we have diminishing marginal product.7.For any…xed level of output q,the set of input vectors producingq is called q-level isoquant.This plays the same role as indi¤erence curve in consumer theory.An isoquant traces out all the combina-tions of inputs that allow that…rm to produce the same quantity of output.8.The substitutability between any pair of inputs x i and x j is themarginal rate of technical substitution(MRTS).MRTS measures the amount of one input i the…rm would require in exchange for using a little less of another input j in order to just be able to produce the same output as before.A q-level isoquant is de…ned as:f(x)=q:Given x ij,let x j(x i)be the amount of x j required to keep out-put constant.If we di¤erentiate the isoquant with respect to x i, holding x ij constant,we get@f @x j dx jdx i+@f@x i=0:Rearranging the terms gives the slopeMRT S ij(x)= dx jdx i=@f@x i@fj:Since f is strictly quasiconcave,MRTS is diminishing.9.Elasticity of substitution:for a production function q=f(K;L);the elasticity of substitution ;measures the proportionate change in K=L relative to the proportionate change in the MRTS along the isoquant.That is,=% KL% MRT S L;K=dK=LdMRT SMRT SK=L=d ln(K=L)d ln MRT S:The shape of the isoquants indicates the degree of substitutability.10.De…nition:we classify the returns to scale of a production function,f(K;L),as follows:E¤ect of Output(m>1)Returns to Scale f(mx)=mf(x)Constantf(mx)<mf(x)Decreasingf(mx)>mf(x)Increasing11.Constant returns to scale means if you multiply all inputs by factorm>1,the output is increased by factor m.Increasing returns to scale means if you multiply all inputs by a factor m,the out-put increases by a factor more than m.That is,you can get proportionally more as you expand.Decreasing returns to scale is just the opposite to increasing returns.A production function can have increasing returns over some range and decreasing returns over another.In fact,a lot of times there is some optimal scale in between:it is ine¢cient to be too small and ine¢cient to be too big.12.Locally,the elasticity of scale at point x is de…ned by(x) limm!1d ln[f(mx)]d ln(m)=P n i=1f i(x)x if(x):1.1Special production functions1.Linear production function:perfect substitutes2.Cobb-Douglas production functionsq=AL K ;where A; ; >0.3.Leontief production functionsq=min K; L :4.CES production functionq=A h L 1 +(1 )K 1 i 1where A>0; 2(0;1); >0. is the elasticity of substitution.(a) =+1,linear production function.(b) =1,Cobb-Douglas production function.(c) =0,Leontief production function.5.Homothetical production function:homothetical production pro-duces a linear expansion path starting from the origin,optimal input ratio at various output level is constant given…xed input prices.2Cost Minimization2.1Long-run Cost minimization1.Some cost de…nition(a)Opportunity cost:the value of a resource in its best alterna-tive use.(b)Sunk costs are those unrecoverable costs that have alreadybeen incurred and the resources have no alternative use.2.Short-run vs.long-run cost minimization(a)Long-run:free to vary quantities of all its inputs as much asit desires.(b)Short-run:unable to adjust the quantities of some of its in-puts.3.Long-run cost-minimization.Let w denote input prices.The costminimization problem is de…ned as:minxwxs:t:f(x) q:L=wx+ (q f(x)):The…rst-order conditions:@L@x i=w i f x i=0;i=1;:::;n@L@=q f(x)=0;From the…rst n equations,we get for all iw if xi= .4.Recall f xi is the extra output the…rm can make from one extraunit input i,so1x i is the amount of input i required to produceone unit of output,and wf xi is the cost for producing one extraunit of output using input i.A cost-minimizing…rm chooses an input combination such that the cost for producing one extra unit of output is the same no matter what input mixes the…rm choose to increase output.5.Example 1:Cobb-Douglas production functionq =50L 1=2K 1=2:MRT S L;K =K L =w r =)K (r;w )=w rL:Plugging K (r;w )into the production functionq =50L 1=2 w r L 1=2=)L =q 50 r w1=2:Similarly,K =q 50 w r 1=2:parative statics of change in output(a)The cost minimizing input combinations,as q 0varies,traceout the expansion path .(b)If the cost minimizing quantities of labor and capital rise asoutput rises,labor and capital are normal inputs .(c)If the cost minimizing quantity of an input decreases as the…rm produces more output,the input is called an inferior input .7.Properties of Cost FunctionIf f is continuous and strictly increasing,then the cost functionc (w;q ) min x wx s:t:f (x ) q is(a)Zero when q =0.(b)Continuous on its domain.(c)For all w >>0,strictly increasing and unbounded above inq .(d)Increasing in w:(e)Homogeneous of degree one in w:(f)Concave in w .(g)Shephard’s lemma:c (w;q )is di¤erentiable in w at (w 0;q 0)whenever w 0>>0;and @c (w 0;q 0)@w i=x i w 0;q 0 ;i =1;:::;n:2.2Conditional Input DemandsSuppose the production function satis…es Assumption 3.1and that the associated cost function is twice continuously di¤erentiable.Then1.x (w;q )is homogeneous of degree zero in w:2.The substitution matrix,0B B B @@x 1(w;q )@w 1@x 1(w;q )@w n::::@x n (w;q )@w 1@x n (w;q )@w n1C C C A is symmetric and negative semide…nite.In particular,the semidef-initeness property implies that for all i@x i (w;q )@w i0.2.3Short-run cost-minimization1.The …rm’s short-run cost minimization problem is to choose quan-tities of the variable inputs so as to minimize total costs,given that the …rm wants to produce an output level q and under the constraint that the quantities of the …xed factors do not change.min xwx + w x s:t:f (x; x ) q:2.Three inputs short-run cost-minimizationmin L;MwL +mM +r K s:t:q =f (L;K;M )Note:L;M are the variable inputs and wL +mM is the total variable cost. Kis the …xed input and r K is the total …xed cost.Tangency condition:MP L w =MP M m:Constraint:q =f (L;K;M ):3.Suppose that K is the long run cost minimizing level of capital foroutput level q .Then when the…rm produces q ,the short-run demands for L and M must yield the long-run cost minimizing levels of L and M4.Exampleq=K1=2L1=4M1=4;r=2;w=16;m=1: The short-run cost-minimization condition when q=16, K=32:(a)Short-run Tangency condition:MP L MP M =ML=wm=161=)M=16L:Constraint16=321=2L1=4(16L)1=4;which gives L=2,and M=16L=32.Thus when q= 16; K=32,the short-run cost minimization inputs combina-tion isL=2;M=32:(b)Long-run cost minimization when q=16:Two tangency conditionMP L MP M =ML=wm=161=)M=16L;MP L MP K =2KL=wr=162=)K=16LConstraint16=(16L)1=2L1=4(16L)1=4=)1634L=16=)L=1614=2: Plugging L=2into tangency conditionM=16L=32;K=16L=32:Hence when K=32is the long-run cost minimizing level of capital for the output level q=16,the short-run cost minimization yields the long-run cost minimizing levels of L and M.5.For the previous example,the long-run cost given input pricesr=1;w=16;m=1isc(q)=8q:The short-run cost…xing K=32issc(q; K)=64+q2 4 :Clearly sc(q; K) c(q)for all q 0:3Pro…t Maximization1.To…nd the optimal outputmaxf q gpq c(w;q) The…rst order condition implies thatp=@c@q(1)and the second order condition is that@2c@q2>0:By the…rst order conditions,we can get the…rm’s output supply function,q =q(p;w):2.To…nd the optimal inputsmaxf x gpf(x) wxUsing the…rst order condition we havep @f@x i=w i;for i=1;:::;n:The…rst-order conditions mean that the marginal revenue product (MRP)of each input i should equal the input price.MRP gives the rate at which revenue increases per additional unit of input i employed.The…rst-order conditions will give us the input demand function of the…rm,x =x(p;w):3.Theorem3.7.If f satis…es Assumption3.1,then for p 0andw 0;the pro…t function(p;w) max pq c(w;q)when well-de…ned,is continuous and(a)Increasing in p:(b)Decreasing in w:(c)Homogeneous of degree one in(p;w):(d)Convex in(p;w):(e)Di¤erentiable in(p;w)>>0.Moreover,(Hotelling’s lemma),@@p=q;@ @wi=x i:4.Theorem3.8.Suppose is well-de…ned and twice continuouslydi¤erentiable,then(a)q and x i are homogeneity of degree zero.(b)The substitution matrix0B B B B B @@q@p@q@w1:::@q@w n@x1(p;w)@p @x1(p;w)@w1::: @x1(p;w)@w n ::::::::::::@x n(p;w)@p @x n(p;w)@w1::: @x n(p;w)@w n1CC C C CAis symmetric and positive semide…nite.In particular,@q 0and@x i(p;w)@w i 0for all i.5.Example:Price P,input prices(w1;w2)q=x 1x 2where ; >0.The…rst order condition givesP x 11x 2 w1=0;(2)P x 1x 12 w2=0;(3)q x 1x 2=0:(4) The…rst two conditions imply that x2= x2=w1=w2and thus, x2=( w1= w2)x1.Plugging it back into(4)yieldsx1=q1 + w2 w1 + ;x2=q1 + w1 w2 + :Plugging the two conditional input demands into (2)gives P q + 1+ w 2w 1 + =w 1=)q+ 1 + =P 1w + 1w + 2 + + =)q =P +1 w + 11w + 12 1 1 ;x 1(P;w )=P 11 w 1 ( + 1)1w ( + 1)2 1 (1 ) 1 ;x 2(P;w )=P 11 w ( + 1)1w 1 ( + 1)2 (1 ) 1 1 :Plugging q (P;w )back into the conditional input demand gives x i (P;w ).And the pro…t function(P;w )=P q (P;w ) wx (P;w ):Note that when + <1,dq (P;w )dP >0@x i (P;w )@w i<0:6.When + =1or + >1;q (P;w )and x i (P;w )are unde…ned,therefore,the pro…t function is not de…ned.To show this,the pro…t function de…ned as before:(p;w ) max pf (x ) wx:Suppose that x 0and f (x 0)maximize pro…ts at p and w:With in-creasing returns,f (tx 0)>tf (x 0)for all t >1:Thus,pf (tx 0) wtx 0>tf (x 0) wtx 0 f (x 0) wx 0for all t >1:This says higher pro…t can always be had by increasing inputs in proportion t >1;which contradicts our assumption that x 0and f (x 0)maximized pro…t.7.Note that in the special case of constant returns,no such problem arises if the maximal level of pro…t happens to be 0.In that case,though,the scale of the …rm’s operation is indeterminate because (f (x 0);x 0)and (tf (x 0);tx 0)give the same level of 0pro…ts for all t >0:4Multiple outputs1.Another way to represent the technology constraint is to think ofthe…rm as having a production possibility set,Y R n;where each vector y=(y1;y2;:::y n)2Y is a production plan,where y i>0means outputs and y j<0means inputs.2.A production plan y2Y is technological e¢cient if there isno b y2Y such that b y>y:A production plan is economically e¢cient if it maximizes pro…ts =py of a given price vector p:3.Economic e¢ciency implies technological e¢ciency.No matterwhat the prices of inputs and outputs are,the…rm needs to achieve technological e¢ciency in order to achieve pro…t maximization.We can think of the…rm’s choice problem in two steps:…rst,the…rm has to achieve technological e¢ciency;second,the…rm obtain eco-nomic e¢ciency on the e¢cient production set or the production possibility frontier(PPF).The PPF is de…ned to be the set of all technologically e¢cient production plans.4.Formally,given a production plan y=(y1;y2;:::y n)2Y;thereis a twice di¤erentiable function G:R n!R that de…nes the production possibility set:Y f y2R n j G(y) 0g:5.Assumption1.Strict Monotonicity.That is,G yi >0;8i;y:By thisassumption,since G yi >0,any y such that G(y)<0is technolog-ically ine¢cient:one can increase the production(or decrease theuse)of one product y i while keeping others constant(some y i areinputs).Therefore,f y2R n j G(y)=0g is the technologically e¢-cient production set and is thus called the production possibilityfrontier(PPF).6.We de…ne the marginal rate of transformation(MRT)asMRT ij @y i@yj =G yjG yi>0:MRT is the slope the PPF.7.Assumption2.G is quasi-convex.The…rm’s problem is then:(p) maxy2R npys:t:G(y) 0:Since technological e¢ciency is necessary for economic e¢ciency (pro…t maximization),the above problem is equivalent to(p) maxpyy2R n s:t:G(y)=0:。