Tomcat 5.5

JDK 5.0

Lomboz 3.2

—————————————

1.修改tomcat:\xxx\server.xml =>tomcat才知道多了這一個webApp

<!– Tomcat Root Context –>
<!–
<Context path=』" docBase=』ROOT』 debug=』0″>
–>
<Context path=』/WebProject』 reloadable=』true』 docBase=』D:\project\WebProject』 workDir=』D:\project\WebProject\work』 />
</Host>
</Engine>
</Service>
</Server>

一個object的所有attribute放在一起,就稱為這個object的state如果一個object的state在object被constructor之後就不再改變,就稱為Immutable Pattern。

優點:

  1. 不能修改一個Imuutable的state,可減少不必要的程式錯誤,所以,一個Immutable object比mutable object容易維護。
  2. 沒有一個thread能修改Immutable object的state,所以Immutable object是thread safe,可節省使用Synchronization的花費

缺點:

  1. 一旦需要修改一個Immutable object,只能建構一個新的同類object,並在constructor時將新的state存在new object中。如果在頻繁修改immutable object的環境中,會有大量的immutable object被產生,再被garbage collection回收,使得效能低落。

week immutable滿足條件:

  1. 所有的attribute必須是private
  2. object的所有method不會改變object的state
  3. 這個object的attribute若包含mutable object,必須限制外界對這些mutable object的存取,防止外界修改這些object。

strong immutable必須還要滿足以下兩個條件之一。

  1. 所有的method都是final,這樣子類別就無法修改。
  2. 這個類別本身就是final,這樣就不會有sub class。
  • 一個類別只能有一個instance
  • 要自行建構這個instance
  • 向整個系統提供這個instance

public class LazySingleton {

//constructor設為private,外界無法直接實體化
private static LazySingleton instance = null;

//外界透過getInstance()來取得instance
public LazySingleton getInstance() {
if (instance == null){
instance = new LazySingleton();
}
return instance;
}
}

函數的定義如下:We will often use the term result for the output, and the terms
arguments or parameters for the inputs.

高階函數至少滿足下列一個條件的函數

  • 接受一個或多個函數作為輸入
  • 輸出一個函數

以下用Haskell為例子,說明High-Order function的應用。

-------------------
利用list comprehension表達

map :: (a -> b) -> [a] -> [b]
map f xs = [ f x | x <- xs ]

filter :: (a -> Bool) -> [a] -> [a]
filter p xs = [ x | x <- xs , p x ]

其中 f ,p皆為function,map、filter本身皆為function,而傳入的parameter(f、p)也為function。傳入的function的定義,必須和map、filter 中function定義符合。

--------------------
利用recursive表達
map :: (a -> b) -> [a] -> [b]
map :: f [] =[]
map f (x:xs) = f x : map f xs

filter :: (a -> Bool) -> [a] -> [a]
filter :: p [] =[]
filter p (x:xs)
| p x = x: filter p xs
| otherwise = filter p xs

f [] =v (v 為initial value)
f(x:xs) = x @ f xs (@為operation)

!!(NOTE)利用這種recursive,可定義出加總乘積 and/or,但可用更高階的角度來看(high order function),定義出foldr

foldr :: (a -> b -> b) -> b -> [a] -> b
foldr f v [] =v
foldr f v (x:xs) = f x (foldr f v xs)
---------------------------------------

例1.利用filter求出list中所有偶數的值

f ::Int -> Bool
f n | n>=5 =True
| otherwise =False
filter f [1,2,3,4,5,6,7,8] =>[5,6,7,8]

傳入filter的function必須return Bool

---------------------------------------

例二.利用map求出二個向量的外積 如[1,3,5] [2,4,6] =>[2,12,30]

myproduct :: Int -> Int -> Int

(因為map2的function定義為接收2個parameter,回傳一個Int)
myproduct x y = x * y

map2 :: (Int -> Int -> Int) -> [Int] -> [Int] -> [Int]
map2 f [][] = []
map2 f (x:xs) (y:ys)= f x y : map2 f xs ys

map2 myproduct [1,3,5] [2,4,6] =>[2,12,30]

---------------------------------------

例三.利用recursive定義出sumproductAND/OR,再用foldr改寫

mysum [] = 0
mysum (x:xs) = x + sum xs

=>mysum[1,2,3,4] =>10

myproduct [] = 1
myproduct (x:xs) = x * myproduct xs

=>myproduct[1,2,3,4] =>24

myAND [] =True
myAND (x:xs) = x && my AND xs

=>myAND[Tue,True] =>True

myOR [] =False
myOR (x:xs) = x || myOR xs

=>myOR[True,False] =>True

利用foldr改寫如下:

  • foldr (+) 0 [1,2,3,4]   =>10
  • foldr (*) 1 [1,2,3,4] =>24
  • foldr(&&)True [True,True] =>True
  • foldr(||)False[True,False] =>True

隨著軟體設計愈來愈複雜,設計軟體的結構顯得愈來愈重要,好的程式結構可加速系統開發的時間,同時也降低了事後維護的成本。本文指出模組化設計為生產力帶來極大的提昇,因為它有以下幾個優點:

  • 小模組的程式碼較容易去撰寫。
  • 模組化的程式可再次的利用,減少開發時間。
  • 模組化程式可以獨立測試。

結構化程式設計是用模組化設計的觀點去思考,將一個大的問題分成數個子問題,再針對每個子問題去解答。而如何將這些子問題結合起來呢?函數化程式設計提供了2種新的思維-高階函數(High-Order Functions)惰性求值(Lazy evaluation)。利用這2點特性將程式模組化成為愈小,越愈能達到功能重複使用的模組,使得後續的程式維護工作變的更簡單。

除了Object 類別的物件之外,所有的Java object都是多型。因為可以通過自己型別的IS-A,,也可以通過Object 類別的IS-A 測試。

interface A{}

class B{ }

class C extends B implements A{…}

任何C類別所產生的object,在任何時後,都可以被多型的對待成下面四種東西之一,至於是那一種,則由reference variable的宣告型別來決定。

  • 一個Object
  • 一個A(C  implements A)
  • 一個B(C extends B)
  • 一個C

雖然可以用父類別來ref子類別的Object,但在Run Time時,會依據實際的object來做動態選擇的只有instance method

定義:修改class、interface、aspect 的成員,來支援dynamic crosscutting

分為以下四種情形:

  • Member introduction
  • Modifying the class hierarchy
  • Introducing compile-time errors and warning
  • exception softening

Advice可看成對Join Point的override,而和method有以下不同的地方:

  • 不可有name。
  • 不能直接呼叫。
  • 不能有access specifier。
  • 可利用thisJointPoint thisJoinPointStaticPartthisEnclosingJoinpointStaticPart來取得和JoinPoint相關的information 。
  • join point中有宣告throw exception,advice中才可throw exception。
  • 可宣告比join point更少或更多的exception。

before():進入Join Point前執行。可用於認証Loggingpolicy實施上。

after():分為三種類型:

  1. 與return value、是否會發生Exception無關:1.jpg
  2. 與return value相關 ,在Join Point成功完整地執行後執行:2.jpg3.jpg
  3. 與throw exception相關,在Join Point丟出一個exception後執行4.jpg5.jpg

around():必須有return type。

  • 可讓Join Point不執行
  • 加入Proceed(),執行Join Point的程式 ,也可修改參數改變其執行。

定義:選取需要的join point,且得到所需的資訊,如target object或method arguments

為了使Pointcuts可以一次設定多個Join points,有以下的幾種規則:

  • * :除了之前出現過的字元
  • .. :包含了之前出現過的字元
  • + :任何的subclass和subinterface

宣告pointCut的Pattern有以下幾種宣告方法:

ff.jpg

而Java中昏class,interface,methods都叫做signatures。我們利用這些signature來指定想要選取的Join Point.有以下三種pattern可表示。

  • Type signature pattern:分別為classinterfaceprimitive types有關。
  1. * : class 或是 interface的一部份,或是 package name
  2. .. : 所有的direct and indirect subpackage
  3. + :  subclass 或是subinterface

 

  • Method and constructor signature pattern
  • Field signature pattern

如何選取所需join point集合形成pointcuts,可依Join Point種類的不同,用以下的幾種方法來操作所找出的pointcuts。

  • Kinded pointcuts:可實現explose join poin

kind.jpg

  • Control-flow based pointcuts

cf1.jpg

  • Lexical-structure based pointcuts:可使用於classaspectmethod的lexical scope。
  1. within(TypeSignaturePattern):使用在找出特定classaspect的join point。
  2. withincode(MethodSignaturePattern,ConstructoruSignaturePattern):使用在找出特定methodconstructor的join point。

le.jpg

  • Execution object pointcuts:可使用於object執行時。
  • 因為傳入的參數為Type,所以不需使用* .. +
    而static method因沒有產生object,所以也不能使用this(),target()。

  1. this(Type or ObjectIdentifier):目前的object。

  2. target(Type or ObjectIdentifier):這個object上的某個method被呼叫。

target() pointcut 一般和call join point 搭配使用。Type:不需要context時使用。this instanceof <Type>True

ObjectIdentifier:需要將context傳給advice時使用,會收集和此object相關的資訊。

exe.jpg

  • Argument pointcuts:抓取有傳遞arguments的join point。

arg.jpg

  • Condition check pointcuts:抓取有選擇的join point。

cond.jpg

可在Join Points中選取所需的Pointcuts , 這些Join Points叫做Expose join points  。以下為各種Expose join points。

  • Method join points
    1. execution join points
    2. call join points
  • Constructor join points
  • Field access join points
  • Exception handler execution join points
  • Class initialization join points
  • Object initialization join points
  • Object pre-initialization join points
  • Advice execution join points

後一頁 »

Follow

Get every new post delivered to your Inbox.