C Legacy.

Uploaded on:
Category: Art / Culture
Nuts and bolts. OO-programming can be characterized as a blend of Abstract Data Types (ADTs) with Inheritance and Dynamic Binding.Encapsulation, legacy and polymorphismEach practice handles an alternate part of framework composition:Encapsulation can be seen as a 2D segment - open and private interfaceInheritance includes an extra measurement - the ADT grabs the qualities of another compone
Slide 1

C++ Inheritance Gordon College CPS212

Slide 2

Basics OO-programming can be characterized as a blend of Abstract Data Types (ADTs) with Inheritance and Dynamic Binding . Exemplification, legacy and polymorphism Each practice handles an alternate part of framework creation: Encapsulation can be viewed as a 2D segment - open and private interface Inheritance includes an extra measurement - the ADT grabs the qualities of another segment. Polymorphism adds to legacy - delaying execution choices (maybe even run-time).

Slide 3

Data Abstraction versus Legacy

Slide 4

Basics Recall that legacy is a method for determining progressive connections between sorts C++ classes can acquire both information and capacity individuals from other (parent) classes Terminology : "the youngster ( inferred or subclass ) sort acquires (or is gotten from) the parent ( base or superclass ) type."

Slide 5

The determined sort is only the base sort in addition to: Added specializations Change execution without changing the base class interface Added Generalizations/Extensions new operations or potentially information

Slide 6

What an inferred class acquires Every information part characterized in the parent class (albeit such individuals may not generally be open in the inferred class!) Every conventional part capacity of the parent class (albeit such individuals may not generally be available in the determined class!)

Slide 7

What a determined class doesn\'t acquire The base class\' constructors and destructor The base class\' task administrator The base class\' companions

Slide 8

What an inferred class can include New information individuals New part works (likewise overwrite existing ones) New constructors and destructor New companions

Slide 9

When an inferred class question is made & crushed Space is distributed (on the stack or the pile) for the full question (that is, sufficient space to store the information individuals acquired from the base class in addition to the information individuals characterized in the determined class itself) The base class\' constructor is called to instate the information individuals acquired from the base class The determined class\' constructor is then called to introduce the information individuals included the inferred class The inferred class protest is then usable When the question is annihilated (leaves scope or is erased) the inferred class\' destructor is approached the protest first Then the construct class\' destructor is brought in light of the protest Finally the designated space for the full question is recovered

Slide 10

Inheritance in C++ The class header is altered to permit a determination list comprising of base classes (C++ permits numerous legacy) class Foo { }; class Bar : open Foo { }; class More : open Foo, open Bar { };

Slide 11

Key Properties of C++ Inheritance The "is-a" relationship is kept up A pointer to the base sort may indicate an inferred sort protest The above relationship consolidated with element restricting - advances a sort secure, polymorphic style of programming The software engineer require not know the real kind of a question at incorporate time (dynamic-official)

Slide 12

Simple Base Class (Screen class) Derived from Screen (Window class)

Slide 13

Derived from Window (Menu class) Inheritance Hierarchy Multiple Levels of Derivation A pointer to an inferred class can be doled out to a pointer of any of its open base classes without requiring an unequivocal cast: Menu m; Window &w = m; Screen *ps1 = &w; Screen *ps2 = &m;

Slide 14

Public versus private legacy people in general catchphrase in the legacy language structure implies that freely available individuals acquired from the base class remain freely open in the inferred class But now and again its desirable over acquire the general population individuals from a parent in a manner that they get to be private in the tyke

Slide 15

Private legacy Public individuals from base class get to be private individuals from determined class Public and ensured individuals are just accessible to determined class part works - not to a determined protest.

Slide 16

Protected legacy private individuals from the base class are not open in the determined class (to safeguard embodiment) Protected capability permits exemplified information individuals which are not freely available to be available by inferred classes ("Protected" individuals are not open from outside the class, with the exception of in determined classes)

Slide 17

Initializer records Derived class constructor naturally calls the "no argument" base class constructor(s) But consider the possibility that a base class has a non-void constructor which should be called. determine which base-class constructor gets called, as a component of the meaning of the inferred class constructor

Slide 18

Initializer records class StatusCoefficient : open Coefficient { open: StatusCoefficient(void) { myStatus = OverStatus; } StatusCoefficient(double initval, Status initStatus) : Coefficient(initval) { myStatus = initStatus; }/ETC. }; class Coefficient { open: Coefficient(void) { myValue = 0; myAccesses = 0; } Coefficient(double initval) { myValue = initval; myAccesses = 0; }/ETC. };

Slide 19

Using Initializer records to instate values Initializer records can likewise be utilized to introduce class individuals with particular esteem (rather than doling out to them in the body of the constructor) class First { open: First() : _foo( "initialize foo first" ), _bar( "then bar" ) { } private: string _foo; string _bar; };

Slide 20

Polymorphism Meaning: some code or operations or articles carry on contrastingly in various settings Example: the + operation carries on diversely relying upon the operands (over-burdening) part work with a similar name would me be able to actualized in various classes Use :: to allude to a capacity in the base class with a similar name - baseCL::function() suitable adaptation of capacity is resolved at runtime – powerfully virtual part works used to execute polymorphism

Slide 21

Polymorphism Dynamic restricting : At runtime the C++ program chooses which part capacity to execute - if the capacity is virtual and exists at the distinctive levels inside a legacy pecking order Contrasts with Static Binding emp.displayEmployeeInfo();

Slide 22

Resources Data Structures with C++, William Ford and William Topp Single and Multiple Inheritance in C++, Douglas Schmidt

View more...