110 likes | 293 Vues
BACS 287. Basics of Object-Oriented Programming 1. What is Object-Oriented Programming?. An approach to programming that combines data and procedures into a single unit (i.e., an object ) This produces a tight coupling between the data and the logic that acts upon the data
E N D
BACS 287 Basics of Object-Oriented Programming 1 BACS 287
What is Object-Oriented Programming? • An approach to programming that combines data and procedures into a single unit (i.e., an object) • This produces a tight coupling between the data and the logic that acts upon the data • Results in natural modular programs that promote code reuse BACS 287
What is Object-Oriented Programming? • Objects can be grouped into hierarchies (i.e., trees) that share characteristics via inheritance • The definition of a type of object is called a class • The template of the objects and their inheritance relationships is called the class hierarchy BACS 287
What is Object-Oriented Programming? • Visual Basic is an object-oriented language • True object-oriented languages involve 3 core concepts: • Inheritance • Encapsulation • Polymorphism BACS 287
Object-Oriented Inheritance • Enables you to create a new object based upon an existing object merely my stating what is different • This is called sub-classing • Example: Class: Vehicle • Sub-Classes: Car, Boat, Airplane • The sub-classes share the basic attributes of vehicle but have differences. The differences are said to “specialize” the super-class. BACS 287
Object-Oriented Encapsulation • Means hiding the implementation details within an object • Only the methods and properties needed to make the object perform are exposed to the application (i.e., the “outside world”) • Enables conceptual abstraction • Visual Basic supports encapsulation well BACS 287
Object-Oriented Polymorphism • Enables different objects to respond to the same message in different ways • Each object type does whatever is most appropriate for the data it contains • For Example: the ADD message would produce different results in objects that held dates, times, strings, and numbers BACS 287
Object-Oriented Terminology • Class (sub-class) • Class Hierarchy • Inheritance • Object (instance) • Properties – characteristic of the object • Methods – procedure that an object to perform • Events – actions or situations that trigger methods BACS 287
Object-Oriented Terminology • Message – what the event sends to the method to trigger it to execute • Encapsulation • Polymorphism • Conceptual abstraction – hiding unnecessary details • Code reuse • Collection – group of objects with something in common BACS 287
Object-Orientation and Event-Driven Programming • Event-Driven programming and Object-Oriented programming are closely related • The event model of the programming language determines the events that the objects can respond to • It is possible to separate the two concepts, but this is normally not done BACS 287
Quiz • What are the 3 key characteristics of an object-oriented language? • What is meant by “conceptual abstraction” • How is “polymorphism” related to the class hierarchy? • What does an “event” trigger? • Is Visual Basic a “true” object-oriented language? BACS 287