16 - Click to edit Master subtitle style Chapter Sixteen...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Click to edit Master subtitle style Chapter Sixteen Modern Programming Languages, 2nd ed. Object Orientation Chapter Sixteen Modern Programming Languages, 2nd ed. 11 Chapter Sixteen Modern Programming Languages, 2nd ed. Definitions Give definitions for the following: Object-oriented language Object-oriented programming Then again, why bother? Chapter Sixteen Modern Programming Languages, 2nd ed. 22 Chapter Sixteen Modern Programming Languages, 2nd ed. Observations Object-oriented programming is not the same as programming in an object-oriented language Object-oriented languages are not all like Java Chapter Sixteen Modern Programming Languages, 2nd ed. 33 Chapter Sixteen Modern Programming Languages, 2nd ed. Outline 16.2 Object-oriented programming OO in ML Non-OO in Java 16.3 Object-oriented language features Classes Prototypes Inheritance Encapsulation Polymorphism Chapter Sixteen Modern Programming Languages, 2nd ed. 44 Chapter Sixteen Modern Programming Languages, 2nd ed. Chapter Sixteen Modern Programming Languages, 2nd ed. 55 public class Node { private String data; private Node link; public Node(String theData, Node theLink) { data = theData; link = theLink; } public String getData() { return data; } public Node getLink() { return link; } } A previous Java example: a node used to build a stack of strings Chapter Sixteen Modern Programming Languages, 2nd ed. Node Class Two fields, data and link One constructor that sets data and link Two methods: getData and getLink In the abstract, an object takes a message (get data, get link) and produces a response (a String or another object) An object is a bit like a function of type message->response Chapter Sixteen Modern Programming Languages, 2nd ed. 66 Chapter Sixteen Modern Programming Languages, 2nd ed. Chapter Sixteen Modern Programming Languages, 2nd ed. 77 datatype message = GetData | GetLink; datatype response = Data of string | Object of message -> response; fun node data link GetData = Data data | node data link GetLink = Object link; Same OO idea in ML. We have a type for messages and a type for responses. To construct a node we call node , passing the first two parameters. Result is a function of type message->response . Chapter Sixteen Modern Programming Languages, 2nd ed. Node Examples Objects responding to messages null has to be something of the object type ( message->response ); we could use Chapter Sixteen Modern Programming Languages, 2nd ed. 88- val n1 = node "Hello" null; val n1 = fn : message -> response- val n2 = node "world" n1; val n2 = fn : message -> response- n1 GetData; val it = Data "Hello" : response- n2 GetData; val it = Data "world" : response fun null _ = Data "null"; Chapter Sixteen Modern Programming Languages, 2nd ed....
View Full Document

This note was uploaded on 09/30/2011 for the course CS 6371 taught by Professor Hamlen during the Spring '11 term at University of Texas at Dallas, Richardson.

Page1 / 44

16 - Click to edit Master subtitle style Chapter Sixteen...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online