Design Pattern final project
資工四 B95902055 李東耿 資工四 B95902060 賈乃輝
1. 計畫
這是一個簡易的 t-shirt 購買的系統,依據消費者的需求來提供不同的服務功 能,也同時提供最快速的服務和活動資訊。讓消費者有完整的購物空間。管理者 提供不同設計師所設計出多元風格的 t-shirt 在此網站系統上販賣,消費者可以進 行選購下單及評鑑,而消費者需核對資料並掌握出貨進度。
2. 系統描述
本系統為一個網路化購物系統,主要由消費者子系統與管理作業子系統所組 成,各子系統分別包括了不同的功能。
消費者:
購物區 (尋找類別 商品瀏覽 熱門 hot 加入購物車)
會員區 (更改資料 更改密碼 購物紀錄)
訂單查詢 (確認/取消訂購 付款方式 出貨狀況)
購物須知
購物區:提供鏈結串列的購物系統,讓消費者快速流覽商品。
會員區:紀錄消費者的基本資料,購物記錄和購物金。
訂單查詢:購物商品確認及更改,商品出貨查詢。
購物須知:讓消費者了解購物資訊和流程。
管理者:
會員資料 (維護會員資料庫 寄發電子報至各會員)
訂單系統 (依序接收訂單資料 核對已收款的項目 結轉收款訂單至 出貨系統)
出貨系統 (商品出貨查詢及確認 商品狀況追蹤)
會員資料:維護會員資料,記錄購物金 更新購物:更新購物資訊。
訂單系統:依客戶訂單內容依序提供商品。
出貨系統:確定訂單商品及出貨方式,到全省便利超商或宅配到府
3. Pattern 的使用
系統的規劃上用到了六種 design pattern
Builder pattern
MVC pattern
Composite pattern
Strategy pattern
Observer pattern
Proxy pattern
1. Builder pattern
The Builder Pattern simplifies the construction of complex objects by only specifying the type and content that the object requires. The construction process of the complex object will therefore allow for different representations of the complex object to be created by the different builders. Each of the concrete builder objects will construct a different representation of the complex object, A client object creates an instance of the Director object and passes it the appropriate Builder object. The Director object invokes the methods on the Builder object to create and initialize specific parts of the Product object. The Builder receives content from the Director object and adds these to the Product object. The Client object has a reference to the Builder object and retrieves the created Product object from it.
and now we can seethe object as the whole order(訂單),and the two representations of the complex object is for customer & manager.
本系統最主要可分為兩組人 customer & manager 的互動,而下訂單的過程中 包含了每筆交易的 id, 金錢和品項,當然還有付款方法和想要取貨的地點,其中 還少不了 customer 所填的個人資料,
ID:id
Money:money Item:item
Pay_way:pay_way Location:location
Personnal_data:personnal_data
而這些繁複的訂單過程和冗長資料可以考慮用 Builder patter 創建出整個 Order class, customer 藉由 Customer_sale 裡 new builder object,
builder.construct_order(), 完成整個訂購程序,透過 getResult(), customer 亦可確 認訂購資料的正確性。相對的 manager 透過 getResult(), 拿到客戶整筆訂單的資 料,之後再藉由 Manager_sale 裡 new builder object, builder.check_order(), 核對客 戶訂單資料的合法性,再決定是否出貨。
2. MVC pattern
對一個購物網站而言,隨著使用者不同的需求,所帶來的各式關鍵字,和不 同的分類標籤,能夠顯示在畫面的商品不盡相同,這樣的機制要有完善的檢索系 統以及和後台資料庫的完整溝通。
而本系統在規劃上,希望能隨著使用者選擇不同的分類按鈕,所展示的 t-shirt 除了順序上會發生改變外,內容可能也會有差異。透過這樣的安排希望透過效率 的檢索能讓使用者能更快速的找到自己想要的產品。
在網站展示 t-shirt 的方式可以用 Model View Controller 來架構。
Model which Models the data and behavior behind the business process, futhermore Responsible for actually doing such like Performing DB queries, Calculating the business, process Processing orders, in addition Encapsulate of data and behavior which are independent of presentation. 我們可將展示出來的t-shirt以及相關的分 類依據都視為此部分。
Controller which Serves as the logical connection between the user's interaction and
the business services on the back, futhermore Responsible for making decisions among multiple presentations, in addition manage different presentation. In other word, a request enters the application through the control layer, it will decide how the request should be handled and what information should be returned.如何讓 label顯示正確的標價,panel顯示在某搜尋條件下,所對應的衣服。這部分的控制 機制在EventListener察覺有任何changeState()會做出因應措施。
View which display information according to client types, and display result of business logic (Model), futhermore not concerned with how the information was obtained, or from where (since that is the responsibility of Model). 靠著JSlider, JLable, Jpanel, 將商品相關的資訊做個呈現。
3. Composite pattern
Composite can be used when clients should ignore the difference between compositions of objects and individual objects. If programmers find that they are using multiple objects in the same way, and often have nearly identical code to handle each of them, then composite is a good choice; it is less complex in this situation to treat primitives and composites as homogeneous.
本系統中有不少t-shirt(concrete_Goods),免不了會因風格描述而有一些分類,另 外管理者也可以透過add(), remove()來管理這些商品,而這些concrete_Goods又需 要透過Itempanel在網站上把相關資料做呈現,此即為Category中每個品項該有的 operation(). 這種樹狀架構的目錄下透過風格而分類出來的子項,由於對每個子 品項而言,不管是管理者或消費者能做的處理都很類似,正來用Composite pattern 來架構。 It makes it easy to add new kinds of T-shirt, and makes clients simpler, since they do not have to know if they are dealing with a leaf(each T-shirt) or a composite Category component. However, it makes it harder to restrict the type of components of a Category.
4. Strategy pattern
We use strategy pattern when people want to pay the bill by different ways. For example, some people prefer using visa as some people would like to pay from their bank account. There is a argument pay_strategy in the Customer class. Each time, customer call pay() or order_goods(Shopping_Cart.g_list), customer can choose one of the payment strategy from the concrete subclass of Pay_strategy. This way, manager can easily extend other payment for customer without more arguments in Customer class.
The flow of buying is that customers need to put all the goods they want to buy in their shopping-carts’ buying list. If customers who want to send out the order must pay the bill first, or the system will ban the order.
5. Observer pattern
When people are browsing the goods they are interested in, there must be some information they may be likely to know. For example, people may wonder the comments from other people, the price, the place, the factory, and the category.
Since, this information may be dynamic and depends on others. We must find some way to update the state of goods. The observer pattern is useful here.
Shopping_Cart and Shopping_area are two concrete subclasses of shooping_list.
Of course, each shopping list will have several goods in general. In order to let the system manager easily add new goods list (ex: some special list of goods about festival) as well as notify all the list contains this good to update. As the state is changed, the notify() function is called by time out or interruption. Then all the list contain the goods will update the state.
Customers can set comment to the goods or set the goods as the candidate to buy through the Shopping_Area and Shopping_Cart classes as well as other people can share some open information in real-time.
6. Proxy pattern
Here, we apply proxy pattern to the user sign in and sign out. Users call
sign_in() and sign_out() function which reference to the object account. Then the system will compare users’ input password and account with the data in database.
Since the account_proxy class has a real_account argument and do the checking step in the real_account class.
The Account will return to the Customer class as a string in a cipher form. This way, the system easily does some optimization according the identity of the user or put some constraints on different users. There are more examples in the following topics.