1 / 10

Programmeerimine Delphi keskkonnas MTAT.03.214

Programmeerimine Delphi keskkonnas MTAT.03.214. Jelena Zaitseva jellen@ut.ee. Design patterns – frequently recurring structures and relationships in object-oriented design. adapter singleton template method factory observer. adapter.

marnin
Télécharger la présentation

Programmeerimine Delphi keskkonnas MTAT.03.214

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programmeerimine Delphi keskkonnasMTAT.03.214 Jelena Zaitseva jellen@ut.ee

  2. Design patterns – frequently recurring structures and relationships in object-oriented design.

  3. adapter • singleton • template method • factory • observer

  4. adapter • PROBLEM: How to resolve incompatible interfaces, or provide a stable interface to similar components with different interfaces? • SOLUTION: Convert the original interface of a component into another interface, through an intermediate adapter object.

  5. singleton • PROBLEM: Exactly one instance of a class is allowed – it is a “singleton”. Objects need a global and single point of access. • SOLUTION: Define a static method of a class that returns the singleton.

  6. singleton • Benefits: • controlled access to sole instance • reduced name space • permits refinement of operations and representations • permits a variable number of instances

  7. template method • template method – “define the skeleton of an algorithm in an operation, deferring some steps to subclasses” Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.

  8. template method • The pattern is essentially an extension of abstract methods to more complex algorithms.

  9. factory • PROBLEM: Who should be responsible for creating objects when there are special considerations, such as complex creation logic, a desire to separate the creation responsibilities for better cohesion, and so forth? • SOLUTION: Create an object called a Factory that handles the creation.

  10. Observer • PROBLEM: Different kinds of subscriber objects are interested in the state changes or events of a publisher object, and want to react in their own unique way when the publisher generates an event. Moreover, the publisher wants to maintain low coupling to the subscribers. What to do? • SOLUTION: Define a “subscriber” or “listener” interface. Subscribers implement this interface. The publisher can dynamically register subscribers who are interested in an event, and notify them when an event occurs.

More Related