Presentation is loading. Please wait.

Presentation is loading. Please wait.

An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.

Similar presentations


Presentation on theme: "An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state."— Presentation transcript:

1

2 An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.

3 Gumball machine

4 Telephone: State: onhook, offhook, inuse Action: pickup, dialing, hangup

5 States Action: Call/email/store front Put everything together Put in the oven Take out of oven Box it

6 Amazon order State: Order received Pending Ship Now Delivered Action: A buyer checkout Process order information and packaging Send to UPS for shipping UPS drop off the order

7 Games: States: standing, jumping, ducking, and diving. Actions: bbutton presses and releases.

8 Car:

9

10 Gumball machine

11 State Machines 101

12 Managing States

13 Managing actions

14 Creating the implementation Source code

15 New Design

16

17

18

19

20

21 State Implementation of Gumball machine Look at Eclipse code

22 State Pattern defined The State Pattern allows an object to alter its behavior when its internal state changes. The object will appear to change its class.

23 State Pattern Class Diagram state

24 Adding winner state Look at source code

25 Comparison of patterns

26 Summary so far.. OO Basics Abstraction Encapsulation Inheritance Polymorphism OO Principles Encapsulate what varies Favor composition over inheritance Program to interfaces not to implementations Strive for loosely coupled designs between objects that interact Classes should be open for extension but closed for modification. Depend on abstracts. Do not depend on concrete classes. Only talk to your friends Hollywood principles: don’t call us, we will call you. Depend on abstracts. Do not depend on concrete classes. A class should have only one reason to change.

27 Summary so far… OO Patterns Strategy Pattern defines a family of algorithms, Encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it. Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically. Decorator Pattern – attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative for sub-classing for extending functionality Singleton Pattern – ensure a class only has one instance, and provide a global point of access to it The Adapter Pattern converts the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces. The Façade Pattern provides a unified interface to a set of interfaces in a subsystem. Façade defines a higher level interface that makes the subsystem easier to use. The Template Pattern defines steps of an algorithm. Subclasses cannot change the algorithm (final). It facilitates code reuse. The Factory Method – Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory method lets a class defer instantiation to the subclasses. The State Pattern allows an object to alter its behavior when its internal state changes. The object will appear to change its class.

28


Download ppt "An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state."

Similar presentations


Ads by Google