140 likes | 252 Views
Presentation by Denis Riordan, Dalhousie University Objects and Classes. Object modeling is a modeling mechanism that maximizes the commonality between situations. Where do we start the modeling process?. What do these objects have in common?. Taxonomic Hierarchy. Hierarchical Extensions.
E N D
Presentation by Denis Riordan, Dalhousie University Objects and Classes
Object modeling is a modeling mechanism that maximizes the commonality between situations.
Where do we start the modeling process? What do these objects have in common? Taxonomic Hierarchy
Hierarchical Extensions Purpose: Avoiding Redundancy by using commonality A component B in an hierarchy lies below (extends) another component A if B has all the properties of A Elephants and rhinoceros share the properties of Chordates Locusts and elephants share the properties of Animalia
Class Creation in Java In Java the components of an inheritance hierarchy are called classes. In class definitions are created using the following syntax class ChosenName { // Details }
Class Hierarchical Creation in Java A class A may be extended to create a class B using the following syntax class B extends A { // Details } In Java all class definitions by default extend the universal class which is called Object (just to be as confusing as possible).
Example of class hierarchical extensions in Java class Animalia { //... } class Chordata extends Animalia { //... } class Mamalia extends Chordata { //.. }
Definitions: Classes and Objects • Classes – define object type - blue prints - specifications • An object is the thing itself • This means that there may be many objects of a particular class
Many objects of the same class class Ant{} Ant a1 = new Ant();
Constructing objects in Java In Java a new object is constructed using the following syntax: ClassName objectName = new ClassName(); or ClassName objectName = new ClassName(parameters); Example Ant a1 = new Ant(); Robot r1 = new Robot(Color.red);
Abstract Classes A class is defined to be abstract if it is intended that it should always be extended (perhaps because there might not normally be an object of that type). abstract class Shape {} class Triangle extends Shape {} Might still be abstract!
Angry rhino object chases annoying photographer Exercise on Object Modelling OMEx.doc
And finally Thank you all for your attention Photography by Denis Riordan