.Open CS320/15 OOP and Java .Table .Row Prev 14 Data Abstraction Chapter 2 section 14 + Chapter 11 lab14 C/C++ ADTs .Row ** Project Deadline Phase 2 Phase 2 due in: changed EBNF and draft UML (10pts) .Row 15 OO Programming and Java Chapter 2 section 17 + Java Handout + Chapter 12 lab15 Java101 .Row Next 16 Concurrency and Java Chapter 13 not sect'n 9 lab16 Java102 .Close.Table .Open Preparation Study Chapter 2 section 17 on Java Study the Java Handout. Study the $Notes below. Study chapter 12 (not section 12) on OOP Check out my notes on Java .See http://cse.csusb.edu/dick/samples/java.html Do the review Questions at the end of chapter 12 but don't do any questions on SmallTalk :-(. Hand in answers to 2 or more review questions. .Close .Open Notes . Current Lab Examples Trigger Security Warnings -- Ignore I have 98 Java files prepared over the years for this class .. and most or them were compiled using an older, less secure Java compiler. So your browser may display a security warning. I think the code is safe for your browser to download and run. You can, therefore, tell it to access them. You can probably tell it to accept any applet from my web site quite safely. The problem may be that I have no easy and simple way of `signing` and applet with a `certification` from a trusted authority. . Object oriented designs are about messages Objects compute things by sending messages. Every message is like a function call and goes from one object to another. As a result you can draw a diagram of an OO program that shows the sequence of calls to and from some objects. Here is an example of part of a program that simulates a DiceGame that has two Dice and throws them, and reads their values to work out a score: .Image OODiceGame.gif [DiceGame creates Dice, Plays game by throwing and read their facevalues] The code is in .See ./java/DiceGame.java and .See ./java/Die.java , enjoy! . There are No abstract objects -- just abstract classes All objects are constructed as an instance of a concrete class. An animal is an abstraction... but each cat and dog is a concrete example of an animal. You point at a cat and a dog with the same finger... and always be pointing at an animal. You can have variables that are declared to point at abstraction..... but can not construct abstract objects. You can have variables that are declared to point at abstraction..... and point them at concrete objects derived from the abstraction. .Image 16/ole3.gif Abstract vs Concrete Try out this program: .See ./15.cpp . Objects know how to do things -- Polymorphism Cats and dogs behave the same even if we change their names. Call a cat an animal.... and it still behaves like a cat. . An object behaves the same however we refer to it. In a non-object-oriented language the behavior depends on its name. In an object-oriented language the behavior is determined by the object. .Open An example Base class Person and two extended classes Student and Faculty. Each class defines an output function that displays the name of the Person. Students also display their GPA. Faculty display their rank. .As_is Person * pointer; .As_is Faculty dick; .As_is pointer = & dick; .As_is pointer->output(); // name and rank .As_is Student jo; .As_is pointer = &jo; .As_is pointer->output(); // name and GPA .As_is pointer = new Student(...); .As_is pointer->output(); // name and GPA .Close . Polymorphism in C++ C++ is a hybrid language. Polymorphism is an option. The default is to cast objects. In other words to change the type of an object to a more abstract type. This can result in programs that have bugs. If an object is assigned to another object of a more general (base) type, the specific data is stripped away. It behaves according to the general rules. This happens with pass-by-value! So in C++ always .Set Use pass by reference and pass by constant reference Do not use rather pass by value. Declare member functions to be virtual. Refer to objects via pointers. .Close.Set . Full Object-Orientation Fully object-oriented languages (Java, SmallTalk, etc.) use late (dynamic) binding by default and these errors are avoided. The cost is that the program runs slower. .Close Notes . Class Work .See http://www/dick/cs320/15q.html . Lab Work .See ./lab/15.html . Next .See ./16.html