IS 437 Fall 2004 Instructor Dr Boris Jukic
IS 437: Fall 2004 Instructor: Dr. Boris Jukic Object Oriented Programming
Learning Objectives • Object-oriented concepts • Implementation of object-oriented concepts in Visual Basic. Net
Limitations Of Conventional Languages o o o Small Vocabulary Highly Procedural Logic Buried In Long Lines Of Code Difficult To Re-Use Code Costly To Build And Modify Allow Only Simple Data Structures
Object-Oriented Approach PROGRAMMING LANGUAGES : SMALLTALK, C++, Java, Visual Basic. Net
Goals To Achieve Greater Semantic Expressiveness - Complex Structure - A Variety Of Relationships - Natural Representation To Reduce Use of Procedural Blocks of Code To Enhance Re-Usability
Objects Correspond to Real World Constructs student university cashier car radio ATM sales report ….
Key OO Concepts Object Encapsulation Class Hierarchy And Inheritance Message And Polymorphism
Object & Encapsulation Everything Is Modeled As Object: Millie Buddy Snoopy Dog Cashier A Tax Return Each Object Has A Name (External Identifier) An Object Has Two Components : - Properties (To Store Information) Can Take On Complex Structure : E. G. : Widget_A (Acquisition_Date, Quantity On Hand) (( 3/10/92 $100) ( 3/20/92 $150) ( 3/25/92 $200)) - Methods (Behavior Encapsulation)
Record structure in COBOL Name Social Security # Hobby John Smith 445 -09 -2049 Swimming Mary Scott 670 -37 -4095 Bridge Bill Shoemaker 888 -92 -9104 Dancing John Smith 123 -87 -3094 Painting Records have no common external identifiers. Attributes are single-valued.
Class Example instance-of relationship MILLE DOG PUPPY DOG(COLOR, SPEED) SNOOPY
Class Hierarchy Example IS-A-Kind of relationship ANIMAL BIRD DOG FISH POLLY MILLIE MOBY instance-of relationship GENERALIZATION-SPECIALIZATION RELATIONSHIP
Class Hierarchy: Another Example IS-A-Kind of relationship UNDERGRADUATE STUDENT MBA STUDENT PH. D. STUDENT
Inheritance ANIMAL (Beak, Fly) BIRD POLLY (COLOR, SPEED) (Bark, Ears) DOG FISH MILLIE MOBY
Polymorphism n n Ability to take on many shapes and forms Many classes can provide the same property or method, without having to worry what type of class it is: n n ¡ n Dog class (eat() method) Mosquito class (eat() method) Of course, same method would be implemented in a very different way Same class can have multiple versions of the method ¡ Overloaded methods
Benefits Of OO Approach: - Greater Semantic Expressiveness Can Represent Is_A Relationships Support Complex Data Structure - Behavior Encapsulation Facilitates The Modeling Of Real-World Objects - Object Library (Re-Use) - Reduce Procedurality Through An Enlarged Vocabulary
Difficulties n Different Programming Paradigm ¡ n Resistance, Requires a shift in thinking) Increased Complexity: ¡ Takes time to become acquainted with the library of objects
Implementation of OO in Visual Basic. Net ü Object ü Encapsulation (property and method) ü Classes: over 6, 000 in number ü Class hierarchy and inheritance ü Polymorphism Visual Basic. Net supports all of the key OO concepts. It is a full-fledged OO system.
Object, Class, Encapsulation in VB. Net class Textbox instance-of relationship object Text. Box 1 New keyword: creates a new instance of an object class
New Method in VB. Net • Also called constructor • It is the method that classes use to instantiating objects. Dim label 1 as Label 1 = New Label or Dim label 1 as New Label
Add a control to a form Me. controls. add(label 1) Represents this form Collections of controls on a form Add to the collection The control to be added
A Simplified View of Class Hierarchy in VB. Net IS-A-Kind of relationship Object Component Data Adapter Date. Time. Picker Control Label Picture. Box
Polymorphism in VB. Net • Functionally equivalent methods can have the same name • VB. Net implements polymorphism in various ways: - overloading - overriding - method hiding
Polymorphism in VB. Net: Overloading Messagebox. Show(“Enter numeric data. ”) Messagebox. Show(“Enter numeric data. ”, “Data entry error”) Messagebox. Show(“This is a message. ”, “This is a title bar”, Message. Box. Buttons. OK) … Overloading: methods sharing the same name, for the same object, but with different signatures (argument lists)
Message. Box General Form Messagebox. Show(Text. Message) Messagebox. Show(Text. Message, Titlebar. Text, Message. Box. Buttons) Messagebox. Show(Text. Message, Titlebar. Text, Message. Box. Buttons, Message. Box. Icons)
Polymorphism in VB. Net: Overriding Animal Parent class and child class may have methods with the same name. The method in child class can override the method in parent class. Dog Snoopy Talk method: “I cannot talk” Talk method: “Bark” Snoopy. Talk “Bark”
Polymorphism: method hiding Button 1. Click Customer. Form. Click Checkbox 1. Click …
Namespaces n n Namespaces are file cabinets for classes, similar to the concept of folders. Namespaces can contain classes, other namespaces, etc. Namespaces help organize the vast number of classes into a neat structure. To make use of a class, we need to reference or import the namespace that contains the class.
Namespace Hierarchy System namespace System Windows. Forms namespace Data namespace Drawing namespace System. Windows. Forms System. Data System. Drawing Button Ole. Db namespace System. Data. Ole. Db Label Text. Box Ole. Db provides interaction with MS Access.
- Slides: 28