Object-Oriented Design IT4GIS Keith T. Weber, GISP GIS Director ISU-GIS Training and Research Center
Topics During the balance of this semester, we will pursue and follow two learning threads Object-relational databases The Geo-Web These two threads are interwoven
To understand Object-Relational Databases… We need to understand both relational concepts and Object-oriented concepts (this week)
The Early Days… Computer programming from the caveman era The first PC’s did not have an OS. They had a BIOS and that is where the user (programmer) interfaced. Programs were small, difficult, and quirky. Because PC’s were not really capable of much (kind of a hobbyists toy…like a ham radio operator) programs were simple things. Like printing text on the screen for someone to read. Adding numbers together (a very expensive calculator which required hours of programming to even enable the calculator to work). Programs were written sequentially with line numbers. More complicated programs…those that could NOT be purely sequential because they involved decisions (do you want to add OR subtract) needed to use GOTO statements. Soon the simple sequential programs were bogged down with tons of GOTO’s and the flow was a messy (making them unstable). This programming style was later dubbed spaghetti programming.
The concept of encapsulation! Why…Object-Oriented A brief history of computer programming… The concept of encapsulation! As programs grew larger and more complex AND interacted with the OS and other apps more, the need was born to develop programs in re-usable modules or packets. Thereby reducing redundancy and the program footprint, while increasing the computer users learning curve through the development of common/similar tools (open, save, print, etc)
Today’s Goals We will dissect “Object-Oriented” to learn what it really is and how it relates to object-relational databases What is a class? What is an object? Enable you to identify inheritance, aggregation, and dependency relationships between classes Understand class attributes and object properties Become familiar with new terminology
What is a CLASS? A class is a computer construct representing a concept bound in a cohesive package Some are concrete (i.e., real world) Bank account Rental item Database item Pile Others are abstract Scanner Stream Math
Discovering CLASSES Simple Rule: Look for nouns in descriptions Obviously not all nouns are classes But at least this approach can allow one to create a list of candidate classes
What is an OBJECT An instance of a CLASS That contains meaningful data OBJECTS occupy memory space at runtime If not, they are CLASSES For example: data type vs. double Data type is a class. It exists as a concept and can be used by programmers and GIS analysts, but does not require computer resources until actually used such as when one declares a field as a double in a database table.
A little Quiz… #1 Class or Object? Dog Dog is a generalization of Scooby-Doo Scooby-Doo
A little Quiz (cont’d)… #2 Class or Object? Dog The concept of subclass! Animal Dog is a subclass of the Animal class Animal is a generalization of Dog Scooby-Doo
A little Quiz (cont’d)… #3 Class or Object? Animal The concept of polymorphism! Bird Dog
Questions so far… Give tour
Key Points Many classes already exist and are at our disposal when we design a database We use inheritance to add capabilities to our projects A subclass inherits from its superclass i.e., a child inherits from its parent
Inheritance in the Geodatabase
Defining a CLASS After a class has been identified we can define: The behavior of each class Methods (verbs) And the attributes of each class
Behavior
Relationships Between CLASSES We have learned about inheritance as one (1) relationship between classes There are three (3) important relationships Inheritance Aggregation Dependency
1- Inheritance Is-a relationship Relationship between a more general class (superclass) and a more specialized class (subclass) Every savings account is a bank account DVD rental is a rental
2- Aggregation Has-a relationship Each Dog has a Paw (dog is not a generalization of paw!) One class (Appendages) contains references to another class (Dog)
Inheritance vs. Aggregation Often confused Questions?
Example Car is a Vehicle – Inheritance Car has a set of Tires – Aggregation
3- Dependency Dependency occurs when a class uses or relies on another class This is a Uses relationship Example: an application may depend on the Scanner class to read input
What type of Method behaviors are these? Class Diagram What type of Method behaviors are these? Dependency…a deposit uses a bank account (cannot happen without it)
Attributes
Class Diagram Attributes help define a given class and instantiate it into an object Dependency…a deposit uses a bank account (cannot happen without it)
Dog example Name of the class = Methods= Dog Attributes? Example of inheritance Example of aggregation Example of dependence Attributes? Dog Brainstorm some methods. Inherited methods (is a) inherit from? Animal. What can it inherit from animal. Circulatory system, nervous system…etc. Maybe we need another superclass between animal and dog called mammal? Aggregated methods (has a) paw Dependency (uses) Bark needs a dog...dog class uses the bark class (superclass subclass structure) Health: height, weight, health, name (note, these attributes are not set as they would require memory and computer resources, so they have no state as a class)
Instantiate into an object Three features characterize objects: Identity: specific attribute (property) settings have been made for the class. This distinguishes it from all other objects. State: Describes the data stored in the object WHERE DID THIS COME FROM? Behavior: describes the method in the object's interface through which the object can be used (how do we make the dog bark?) Only an instantiated class (an object) can have a state. It is active and dynamic. If something has a state (status) then it is an object, not a class.
Instantiating the Dog CLASS CLASS (DOG) Attributes (Properties) NAME = Scooby-Doo HEIGHT = 36 WEIGHT = 145 Methods [Uses] bark- “Rooby roo” etc. Scooby-Doo Notice, the properties have a state. This is an object…an instantiation of the dog class.
Key Concepts Understand the difference between a CLASS and an OBJECT Understand new terms: Encapsulation, polymorphism, superclass, subclass, behavior, attributes, instantiation Understand --and be able to differentiate-- the three types of behaviors Inheritance, aggregation, dependency
Questions… Give tour