1 / 24

Representing Structure and Behavior

Representing Structure and Behavior. CS1316: Representing Structure and Behavior. Story. Techniques for representing data structure Arrays, linked lists, circular linked lists, trees, graphs, stacks, queues, event queues Techniques for representing behavior

onan
Download Presentation

Representing Structure and Behavior

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. Representing Structure and Behavior CS1316: Representing Structure and Behavior

  2. Story • Techniques for representing data structure • Arrays, linked lists, circular linked lists, trees, graphs, stacks, queues, event queues • Techniques for representing behavior • Functions (in Python), methods (in Java) • Techniques for representing both • Objects (what they know, and what they know how to do) • Simulations • Functional branches in a tree • Messages in a simulation • Techniques for describing structure and behavior outside a program • UML class diagrams, Abstract Data Types (ADTs) • What’s a program?

  3. The Point of this Course • Real computer-based media developers rarely work in terms of pixels and samples • Computer musicians deal in terms of notes, instruments, patches, and other structures. • Computer animators deal in terms of characters, movement, scenes, and other structures • Bottom-line: They structure their media.

  4. Driving Questions of the Course • How did the wildebeest’s charge over the ridge in The Lion King? • How did the villages wave in The Hunchback of Notre Dame?

  5. The Wildebeests in The Lion King

  6. The Villagers in The Hunchback of Notre Dame

  7. The answer: Modeling and Simulation • These are two of the (rare) times that Disney stepped away from their traditional drawn cel animation. • Instead they: • Modeled the structure of wildebeests and villagers, • Modeled the behavior of wildebeests (how they stampede) and villagers (how they wave), • Then started a computer simulation that executed the models…and basically filmed the screen.

  8. How did they do that?

  9. Data structures and their properties: Arrays • Arrays are efficient in memory • Everything is packed together • Uses no additional memory • Very fast for accessing any individual element • They are hard to insert and delete with. • Have to move everything around • They can’t be grown. • They have a fixed size.

  10. Linked Lists • Uses extra memory to record next • Simple to insert and delete elements within • Reconnect, disconnect • Have to find elements to access them • Can grow as large as memory allows

  11. Circular linked lists • Good for describing data that loops • But don’t try to traverse them using any normal traversal!

  12. Trees • Uses branch nodes that represent both next but children. • In binary trees, every node represents left and right. • All the advantages of linked lists, but can also representing hierarchy or clustering.

  13. Graphs • Like trees, but arbitrary linking. • Anything can link to anything else, including loops. • Good for representing things like highway systems and blood paths and other real things.

  14. Stack • A LIFO (Last In First Out) list. • We described it as an ADT (Abstract Data Type) • What methods it understands (push, pop, peek, size, empty) • What those methods do. • We used it for reversing a list.

  15. Queue • A FIFO (First In First Out) list • We described it as an ADT, too. • We used it to represent agents lining up for a resource in a simulation

  16. Event Queue • It’s a queue where elements are kept in a sorted order. • For us, it was in order of event times. • We needed the earliest time to be at the top of the queue.

  17. Representing behavior • Functions in Python describe behavior. • They take data in as input and act upon it • Sometimes returning other data • Methods in Java describe behavior • They can act just like functions, but they can also manipulate this—the object that the method is part of.

  18. ADT’s • Describing the methods • Push, pop, peek, size, empty • Describing how they work • Pop off the head • Push onto the tail • If you write your programs expecting any implementation of a given ADT, your program will work even when the ADT implementation changes.

  19. Representing both • Objects • Keep instance (and class “static”) data and its structure—what they “know” • Keep methods for describing behavior on that data—what they “know how” • Objects represent both structure and behavior • Objects were originally invented in order to do simulations. • All programs can be thought of as simulations.

  20. Embedding behavior in our structures • Branches in trees that manipulate their children • Scaling in sound trees • Moving and vertical/horizontal placement in picture trees • Messages in simulations are data that trigger behavior • “Now, you’re at the factory”

  21. How do we describe this stuff? • Describing structure and behavior is modeling • Obviously, a program can, but that’s a very detailed description. • Anything easier to grasp, to see without so much implementation detail?

  22. UML class diagrams

  23. What’s a program? • As we started with in CS1315: • A program is a specification of process, so exact that it can be executed by a machine. • It’s the same thing now, at the end of CS1316. • But…

  24. Where’s the program? • The program is embedded in representations of structure and behavior. • It’s in that tree that holds your hierarchy. • And in those messages that tell your agents what to do. • And in how that queue works. • And throughout the insertAfter(), and add(), and last() and other methods of your data structures. • And in ALL those objects that you create and use. • Programs are distributed across your representations of structure and behavior.

More Related