انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة
الكلية كلية العلوم للبنات
القسم قسم الحاسبات
المرحلة 2
أستاذ المادة احمد علي حسين الجنابي
15/02/2017 05:45:12
Implementing Inheritance Object-oriented programming is based on four important aspects: Encapsulation, abstraction, inheritance, and polymorphism. Inheritance is a powerful way to reuse attributes and is a stepping stone towards polymorphism. In this lesson, you find out about ? Inheritance in the context of programming ? The C++ syntax of inheritance ? public , private , and protected inheritance ? Multiple inheritance Basics of Inheritance In programming parlance, we are often faced the situations where components being managed have similar attributes, differing minutely in details or in behavior. One way to solve this problem is to make each component a class where each class implements all attributes, even re-implementing the common ones. Another solution is using inheritance to allow classes that are similar to derive from a base class that implements common functionality, overriding this base functionality to implement behavior that makes each class unique. The latter is often the preferred way. Welcome to inheritance in our world of object-oriented programming, as illustrated by the following Figure.
Inheritance and Derivation Figure (Inheritance between classes) shows a diagrammatic relationship between a base class and its derived classes. It might not be easy right now to visualize what a base class or a derived class could be; try to understand that a derived class inherits from the base class. Note: This lesson starts with public inheritance to understand the concept of inheritance and the most frequent form of inheritance before moving on to private or protected inheritance. To make understanding this concept easy, think of a base class Bird. Classes are derived from Bird are class Crow, class Parrot, or class Kiwi. A class Bird would define the most basic attributes of a bird, such as is feathered, has wings, lays eggs, can fly (for the most part). Derived classes such as Crow, Parrot, or Kiwi inherit these attributes and customize them (for example, a Kiwi would contain no implementation of Fly(). Table 1 demonstrates a few more examples of inheritance.
What these examples show is that when you put on your object-oriented programming glasses, you see examples of inheritance in many objects around yourself. Fish is a base class for a Tuna because a Tuna, like a Carp, is a Fish and presents all fish-like characteristics such as being cold-blooded. However, Tuna differs from a Carp in the way it looks, swims, and in the fact that it is a saltwater fish. Thus, Tuna and Carp inherit common characteristics from a common base class Fish, yet specialize the base class attributes to distinguish themselves from each other. This is illustrated in the following Figure.
المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .
الرجوع الى لوحة التحكم
|