1. Trang chủ
  2. » Cao đẳng - Đại học

Slide phân tích và thiết kế phần mềm

34 5 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 34
Dung lượng 1,39 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Style for Describing Patterns• We will use this structure: • Pattern name • Purpose: what problem the pattern addresses and the general approach of the pattern • UML for the pattern • Pa

Trang 1

Design Patterns

nlhdung@fit.hcmus.edu.vn

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 2

What Are Design Patterns?

• Solutions to common problems

• Targets of refactoring, not design

• Powerful, flexible, reusable

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 3

Pattern Types

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 5

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 7

Style for Describing Patterns

• We will use this structure:

• Pattern name

• Purpose: what problem the pattern addresses

and the general approach of the pattern

• UML for the pattern

• Participants: a description as a class diagram

• Use Example(s): examples of this pattern, in C#

and other

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 8

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 9

Singleton - Purpose

• This pa(ern ensures that a class has only one

instance and provides a global point of access to it.

• Exactly one instance of a class is required.

• Controlled access to a single object is

necessary

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 10

Singleton - UML

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 11

Singleton – Sample 1

Eager initialization of singleton

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 12

Singleton – Sample 2

lazy initialization of singleton

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 13

Singleton – Sample 3

Thread safe initialization of singleton

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 14

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 15

Composite - Purpose

• This pattern is used to separate an

abstraction from its implementation so that both can be modified independently

• It is used when we need to treat a group of objects and a single object in the same

• It creates a class contains group of its own objects This class provides ways to modify its group of same objects

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 16

Composite – When to use

• Hierarchical representations of objects are required.

• The Composite pattern is used when data is organized in a tree structure

• A single object and a group of objects

should be treated in the same way.

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 17

Composite – UML

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 18

Composite – UML (2)

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 19

Composite – Sample

• The classes, interfaces and objects:

• IEmployed - Component Interface.

• Employee- Composite Class.

• Contractor- Leaf Class

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 20

Composite – Sample

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 21

Composite – Sample

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 22

Composite – Sample

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 23

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 24

Prototype - Purpose

• Create objects by cloning a prototypical instance.

• Consumes less resources than creating new objects.

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 25

Prototype – UML

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 26

Prototype – Sample

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 27

Prototype – Sample

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 28

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 29

Template - Purpose

• This pattern is used to define the basic

steps of an algorithm/task and allow the

implementation of the individual steps to be changed

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 30

Template – UML

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 31

Template – Sample

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 32

Prototype – Sample

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 33

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Trang 34

Reference:

• Erich Gamma, John Vlissides, Ralph Johnson, and Richard Helm, “Design Patterns: Elements of

Reusable Object-Oriented Software”, 1994

• Bert Bates, Kathy Sierra, Eric Freeman, Elisabeth Robson, “Head First Design Patterns”, 2009

CuuDuongThanCong.com https://fb.com/tailieudientucntt

Ngày đăng: 06/12/2021, 16:27

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN