1 / 11

Understanding State-Based Systems and Polymorphism in Computer Science

This guide introduces fundamental concepts of state-based systems and polymorphism in computer science. It details how a system's behavior is influenced by its current state, exemplifying with real-world devices like cable boxes and cell phones. Additionally, it explains polymorphism, where an object's method dictates its behavior, irrespective of the reference type. Through a concrete example using the State and Proxy design patterns, this text provides insights into delegation and state management in programming through a DeskLamp class.

arawn
Télécharger la présentation

Understanding State-Based Systems and Polymorphism in Computer Science

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. CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739 alphonce@buffalo.edu

  2. State systems • State-based system: • system’s behavior based on its current state • Many systems are state-based: • Cable/Satellite TV box • Wrist-watch • Cell phone interface

  3. State Diagram push button OFF ON push button

  4. State Pattern example

  5. Polymorphism • Behavior determined by method of object, because… • it’s the object that responds: • the type of the object determines response • the type of the reference to object doesn’t

  6. Polymorphism declared type of variable a supertype of actual type of object

  7. Proxy Pattern Polymorphism

  8. Polymorphism(in proxy pattern) context delegates method call to concrete tool

  9. State Pattern delegation

  10. Delegation in State code public class DeskLamp { private IState _state; public DeskLamp() { _state = new Off(); } public void pushButton() { _state.pushButton(this); } public void setState(IState s) { _state = s; } }

More Related