I T P TH C HÀNH
Môn TKPMHDT
---
Bài th c hành s 06: Structural Patterns
1. T o m t Project m i trên EA. T o s đ l p cho 7 m u Structural t Pattern tích ơ
h p s n trong EA.
2. Thay đ i tên l p trong các m u này đ t o ra nh ng d c th (nh d trong ư
GangOfFour).
H ng d nướ : Xem ph n Help c a EA, m c Pattern Default, change
Use a Pattern
Using a Pattern enables you to use items defined in the Pattern with the UML model. Using
Patterns enables you to rapidly create template solutions for code structures that perform the
same type of task in other situations.
To use a Pattern that you have previously imported into the model, follow the steps below:
1. Open the diagram into which to add the UML Pattern.
2. Select the Resources window.
3. Expand the UML Pattern folder and find the Pattern to add.
4. Either:
Right-click on the Pattern and select the Add Pattern to Diagram menu option or
Drag and drop the Pattern from the Resources window onto the diagram.
5. Once the appropriate selections have been made, click on the OK button to import the
Pattern into the model, recreating the original diagram with new GUIDs.
Change Pattern Element Default
To change the default of the Pattern element, follow the steps below:
1. From the Add Pattern dialog select the individual element in the Pattern Element panel.
2. Click on the [ ... ] button to display the Edit dialog. The specific method for changing the
element name is dependant upon the entry in the Action column of the Pattern Elements
panel.
3. If the Action entry is Create, then in the Default field in the Edit dialog delete the existing
value and type your own, user-defined value. Click on the OK button. The element default
is updated on the Add Pattern dialog.
4. If the Action entry for the element is Merge, in the Edit dialog click on the [ ... ] button to
browse to an existing element classifier. The Set Element Classifier dialog displays.
5. Select an existing element classifier from the Classifier list. You can restrict the number
of choices by selecting the elements from a specific namespace; to do this, click on the In
Namespace drop-down arrow and select a namespace. For more information regarding
setting element classifiers see the Using Classifiers topic.
3. Import 7 m u structural t code GangOfFour vào. L u ý: t ch c thành các Package ư
riêng cho t ng m u. M i d ng (Structural, RealWorld, .NETOptimized) bi u di n
trong m t l c đ l p riêng. ượ
4. M ph n code c a GangOfFour trên Visual Studio, copy ph n m u FlyWeight
(RealWorld) sang m t Project m i. K t h p Singleton vào m u FlyWeight này đ ế
đ m b o ch t o 1 th c th duy nh t cho FlyWeightFactory. Import l i s đ l p cho ơ
ph n code đã đi u ch nh. Quan sát k t qu xem đã phù h p hay ch a. ế ư
5. K t h p FlyWeight v i Composite đ x lý sao cho các LeafNodes (Primitives) đ cế ượ
chia s gi a nhi u đ i t ng (ph c h p) khác nhau. L p s đ l p cho m u lai này. ượ ơ
Phát sinh code hoàn ch nh ph n cài đ t cho d RealWorld c a Composite,
sau khi đã k t h p FlyWeight.ế
-H T BÀI 6-