Download presentation
Presentation is loading. Please wait.
Published byJeffry Blair Modified over 9 years ago
1
Understanding the use of classes in OOD
2
What makes a class a class? Basically two things Abstraction – the method of creating general terms for an item Encapsulation – the method of stuffing that item with the functionality and data that pertain to it The characteristic of OOD that says that how a class operates is nobody’s business but its own
3
Abstraction An object is an abstraction It is considered a generalized form of something without a specified type Example An automobile would be a class that is very generalized because it has properties and functionality that are common to all automobiles regardless of whether they are cars, trucks, SUV, or busses
4
Identifying a class An easy way to identify a class for something is to put it into this phrase “A ____ is a type of ___.” A car is a type of automobile A truck is a type of automobile A bus is a type of automobile Although automobile is a class it can be abstracted as well An automobile is a type of transportation A plane is a type of transportation A ship is a type of transportation
5
Encapsulation The characteristic of OOD that says that an object shall operate as a black box Black box – term used for something that has known functionality but the means in which this functionality is carried out is unknown Input Send input into black box Black Box See the final result Output
6
Interfaces A means by which to hide functionality from the user With a procedural design without encapsulation, everything is exposed Pieces of functionality begin to interfere with one another very easily, because no interfaces are designed Business rules sometimes get bypassed because procedures that implement them do not need to be called Creates spaghetti code – the lines of operation are tangled because any piece of functionality can call any other piece of functionality
7
Interfaces (cont’d) The OO development the use of encapsulation and exposure through interfaces helps maintain coherence in your software Example: Create objects to store data Create objects to display data Create objects that carry out business logic on your data
8
Understanding the use of inheritance in OOD Inheritance is a way of allowing one class to gain (inherit) the functionality of another class Permits code to be written once and reused throughout the application The advantage of smaller, cleaner code Permits changing a piece of functionality in one place to fix the entire application Inheritance allows your system to have a class that does everything another class does plus more
9
Inheritance (cont’d) Assume for a moment we have two class These classes have common functionality that can be shared between the two SubclassA is derived from Superclass Superclass SubclassASubclassB
10
Inheritance (cont’d) The new diagram is showed on the right.
11
Inheritance hierarchies Inheritance can span multiple levels A superclass to a subclass can also be a subclass to a superclass SubclassA Superclass SubclassB SubclassA1SubclassA2SubclassB1SubclassB2
12
Inheritance hierarchies (cont’d) Example Car Automobile Truck SedanSportsCarTractorTrailerPickup
13
Inheritance hierarchies (cont’d) Example cont’d
14
Multiple Inheritance Classes can be derived from more than one superclass
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.