היצביט ומ - ןוכית ת וי נבת

Similar documents
CHAPTER 6: CREATIONAL DESIGN PATTERNS

Object-Oriented Design

הנדסת תוכנה 11. מבוא לתבניות תיכון. se15b-yagel 1

An Introduction to Patterns

What is Design Patterns?

הנכות 1 תואיגש םע תודדומתהו תואלול,םי : כרעמ 2 לוגרת

הנכות 1 תואיגש םע תודדומתהו תואלול,םיכרעמ : לו 2 גרת

תוכנה 1 תרגול 2: מערכים, מבני בקרה ושגיאות

Using Design Patterns in Java Application Development

Design Patterns. Gunnar Gotshalks A4-1

Object Oriented Methods with UML. Introduction to Design Patterns- Lecture 8

תוכנה 1 תרגול 2: מערכים ומבני בקרה

SOFTWARE PATTERNS. Joseph Bonello

Facade and Adapter. Comp-303 : Programming Techniques Lecture 19. Alexandre Denault Computer Science McGill University Winter 2004

תוכנה 1 סמסטר א' תשע"א

Advanced Object Oriented PHP

CHAPTER 6: CREATIONAL DESIGN PATTERNS

What is Design Patterns?

Design Patterns For Object Oriented Software Development Acm Press

An Introduction to Patterns

Lecture 13: Design Patterns

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

Pattern Resources. Lecture 25: Design Patterns. What are Patterns? Design Patterns. Pattern Languages of Programming. The Portland Pattern Repository

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming

Object Oriented Programming. Michał Bereta

Patterns. Erich Gamma Richard Helm Ralph Johnson John Vlissides

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

James Newkirk

Software Design COSC 4353/6353 D R. R A J S I N G H

Applying the Observer Design Pattern

Review Software Engineering October, 7, Adrian Iftene

The GoF Design Patterns Reference

What is Design Patterns?

Tuesday, October 4. Announcements

Bugsquashing: Command - Pattern. Andreas Fetzer

תוכנה 1 מערכים. Array Creation and Initialization. Array Declaration. Loop through Arrays. Array Creation and Initialization

תוכנה 1 מערכים. Array Creation and Initialization. Array Declaration. Array Creation and Initialization. Loop through Arrays

תוכנה 1 3 תרגול מס' מערכים ומבני בקרה

מבוא למדעי המחשב תרגול 8 רשימה משורשרת כללית, Comparator

w3.ualg.pt/~jvo/poo

Model-View-Controller

Design Patterns. An introduction

Applying the Decorator Design Pattern

Design Patterns: Part 2

6.170 Lecture 15 Design Patterns

Design Patterns. Observations. Electrical Engineering Patterns. Mechanical Engineering Patterns

CPSC 310 Software Engineering. Lecture 11. Design Patterns

Exception Handling Alternatives (Part 2)

MVC. Model-View-Controller. Design Patterns. Certain programs reuse the same basic structure or set of ideas

הקלחמ ה תמרב ת ונ וכ ת (static members ) יליזרב דהוא Java תפשב ם דקת מ תונכת ביבא ל ת תטיסרבינוא

Applying Some Gang of Four Design Patterns CSSE 574: Session 5, Part 3

Topics in Object-Oriented Design Patterns

Object-Oriented Design

Design Patterns. CSC207 Fall 2017

THE DESIGN PATTERNS JAVA COMPANION JAMES W. COOPER. Copyright 1998, by James W. Cooper

CS 351 Design of Large Programs Singleton Pattern

C++ INTERFACE CLASSES STRENGTHENING ENCAPSULATION

מצליחה. 1. int fork-bomb() 2. { 3. fork(); 4. fork() && fork() fork(); 5. fork(); printf("bla\n"); 8. return 0; 9. }

Applying the Factory Method Design Pattern

COMM1003. Information Theory. Dr. Wassim Alexan Spring Lecture 4

Crash course on design patterns

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3

הנכות 1 םוכיס לוגרת 13 1

Configuration Provider: A Pattern for Configuring Threaded Applications

DESIGN PATTERN - INTERVIEW QUESTIONS

מבוא לתכנות בשפת C. Tzachi (Isaac) Rosen

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Nat. Thomas Software Engineering Telephonics Inc. Long Island IEEE Lecture Series

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

An Expert System for Design Patterns Recognition

תכנות מונחה עצמים משחקים תשע"ו

Practical Session - Heap

Design Patterns. CSC207 Fall 2017

Introduction and History

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

Object-Oriented Software Development Goal and Scope

Outline of today s class. Design Patterns. Classes and Inheritance. Aside: UML Class Diagrams

2.1 Design Patterns and Architecture (continued)

Design Patterns (1) CSE 331 University of Washington

2.1 Design Patterns and Architecture (continued)

הנכות 1 םוכיס לוגרת 14 1

Foundations of Software Engineering Design Patterns -- Introduction

Introduction To Design Patterns

Coordination Patterns

מערכים שעור מס. 4 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1

עידן ה- Web 3.0. ל- Web Semantic ו- Web 3.0. Info April 2008

פיתוח מ ע רכות תוכנ ה מבוססו ת Java אוהד ברזילי

developer.* The Independent Magazine for Software Professionals Factory Chain: A Design Pattern for Factories with Generics by Hugo Troche

Chapter 19a Pronominal Suffixes Introduction

Second Midterm Review

Software Engineering - I An Introduction to Software Construction Techniques for Industrial Strength Software

Towards a Java Framework for Knowledge Representation and Inference

Design Patterns. CSC207 Winter 2017

Cocoa Design Patterns. Erik M. Buck October 17, 2009

Object Design II: Design Patterns

JOURNAL OF OBJECT TECHNOLOGY

Slide 1. Design Patterns. Prof. Mirco Tribastone, Ph.D

תוכנה 1. תרגול מספר 11: Static vs. Dynamic Binding מחלקות מקוננות Nested Classes

Introduction To Design Patterns. You will learn about design techniques that have been successfully applied to different scenarios.

Software Reengineering Refactoring To Patterns. Martin Pinzger Delft University of Technology

Transcription:

תבני ו ת תיכון Patterns) (Design

תבנ יו ת תיכון - מו טיבציה בחיי היום יום אנחנו מתארים דברים תוך שימוש בתבניות חוזרות: "מכונית א' היא כמו מכונית ב', אבל יש לה 2 דלתות במקום 4" "אני רוצה ארון כמו זה, אבל עם דלתות במקום מגרות" גם בפיתוח תוכנה, אנחנו יכולים להסביר כיצד לעשות משהו ע"י התייחסות לדברים שעשינו בעבר, ובצורה כזאת להקל על התקשורת עם עמיתים. "נאחסן את המבנה בעץ בינרי, ונבצע חיפוש לרוחב" 2

תבנ ית תיכון - הגדרה תבנית תיכון: פיתרון מקובל לבעיית תיכון נפוצה בתכנות מונחה עצמים. התבנית אינה מתארת אלגוריתם ספציפי, אלא קשר בין המחלקות הגדרות מהספרות: "Design Patterns are recurring solutions to design problems you see over and over." [Alpert, Brown, Wof, 1998]. "Design Patterns constitute a set of rules describing how to accomplish certain tasks in the realm of software development." [Pree, 1994]. "A pattern address a recurring design problem that arises in specific design situations and presents a solution to it." [Buschmann et al., 1996]. "Patterns identify and specify abstractions that are above the level of single classes and instances, or of components." [Gamma et al., 1993]. 3

מקורו ת המושג נעשה פופולרי בעקבות הספר שמכונה GoF המכיל דוגמאות קוד ב ++C Design Patterns: Elements of Reusable Object-Oriented Software By Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides. Published by Addison Wesley Professional. Series: Addison-Wesley Professional Computing Series. ISBN: 0201633612; Published: Oct 31, 1994; Copyright 1995; Pages: 416; Edition: 1st. 4

מקורו ת ב Java קיימים כמה מקורות לתבניות עיצוב עם דוגמאות בשפת Java כגון: The Design Patterns Java Companion James W. Cooper http://www.patterndepot.com/put/8/javapatterns.htm Thinking in Patterns with Java Bruce Eckel http://www.mindview.net/books/tipatterns/ Data Structures and Algorithms with Object-Oriented Design Patterns in Java http://www.brpreiss.com/books/opus5/ תבניות עיצוב רבות אומצו ע"י כותבי הספריות הסטנדרטיות של Java בעיקר (אבל לא רק) בספריות GUI 5

סי וו ג תבני ות 6 בספר GoF יש 23 תבניות שמחולקות ל- 3 סוגים תב נ יו ת יצירה :(Creational) תב נ יו ת מבנה :(Structural) לפי מטרתן: נוגעות לתהליך היצירה של עצ מים. עוסקות בהרכ ב ה של מחל קות וע צ מים. תבניות התנהגות :(Behavioral) מאפיינות את הדרכים בהן מחלקות ועצמים מתקשרים ומחלקים אחריות. סיווג אחר: לפי תחום בנוסף, ניתן להתייחס כלל ביחד: עיסוק התבנית מחלקות או עצמים. לקבוצות של תבניות שמופיעים בדר ך כ אלה שמהווים חלופות שונות לפתרון בעיות דומות פתרונות דומים לב עיות שונות לתבניות חשיבות גדולה באפיון הבעיות חל ק מהתבניות ראינו במהלך ה קורס בהק שר רחב או מקומי

סי וו ג תבני ות 7

Factory The new operator gets a class name, (no an interface or an abstract class): VersionedString vstring = new LinkedVersionedString(); interface A factory returns VersionedString one of several classes with the same interface or super-class class LinkedVersionedString class BoundedVersionedString 8

Factory (cont.) VersionedString vstring = VersinedStringFactory.construct(); interface VersionedString class VersionedStringFactory construct() class LinkedVersionedString class BoundedVersionedString constructs different instances of VersionedString 9

Abstract Factory Useful for creating families of related objects without specifying their concrete classes Example: An application for building cars builds various types of cars: Hundai-Accent, Peuget 205 GTI, Fiat-Uno etc. all cars have the same overall structure, i.e. consist of the same components: engine, wheels, brakes etc. The components are different. 10

Abstract Factory (cont.) abstract CarFactory CarBuilder createengine() createwheel() abstract Wheel Client FiatUnoWheel HundaiAccentWheel HundaiAccentFactory createengine() createwheel() FiatUnoFactory createengine() createwheel() abstract FiatUnotEngine Engine HundaiAccenEngine 11

Abstract Factory (cont.) Isolates concrete classes Exchanging product families is easy Promotes consistency among products Supporting new kinds of products involves changing the AbstractFactory class and all of its subclasses. Typically implemented as a singleton. 12

Singleton Ensures a class has only one instance and provides a global access point to it. public class Logger { private static final Logger instance = new Logger(); private Logger() { } public static Logger getinstance() { return instance; } } 13

Singleton (cont.) public class Logger { private static Logger instance; ` } private Logger() { } public static Logger getinstance() { if (instance == null) instance = new Logger(); return instance; } Lazy evaluation (not thread-safe) 14

Object Pool Database Example: Task: Design a class for accessing a DB Client. Network Connections Database Server Database Client Our Class 15

Object Pool (cont.) Constraints: Establishing and cleaning up connections to a database are time-consuming Connecting/Disconnecting time may depend on the number of open connections. The number of open connections may be limited (server capacity, DB license) Solution: Maintain a pool of open connections for reuse 16

Object Pool (cont.) Singleton DBConnectionPool private DBConnectionPool(); public static DBConnectionPool getinstance(); public int getmaxsize(); public DBConnection acquire(); public release(bpconnection connection); Client may throw an EmptyPoolException cannot be constructed by clients. DBConnection protected DBConnection(); 17

Reference Objects Consider the following case: we have an unlimited pool of DB connections we may end up in an out of memory situation To overcome this problem: The pool will use soft references to hold DB connections Unused connections will be cleared by the garbage collector if memory is required. 18