programming pillars
DESCRIPTION
Programming Pillars. Inheritance Part 2. Lecture Overview. Abstract classes. Abstract Classes (Introduction). Abstract classes define an interface The implementation is either undefined or partially defined It's not possible to create an instance of an abstract class - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Programming Pillars](https://reader036.vdocument.in/reader036/viewer/2022083006/56813ddf550346895da7ae3c/html5/thumbnails/1.jpg)
Programming Pillars
Inheritance Part 2
![Page 2: Programming Pillars](https://reader036.vdocument.in/reader036/viewer/2022083006/56813ddf550346895da7ae3c/html5/thumbnails/2.jpg)
Slide 2
Lecture Overview Abstract classes
![Page 3: Programming Pillars](https://reader036.vdocument.in/reader036/viewer/2022083006/56813ddf550346895da7ae3c/html5/thumbnails/3.jpg)
Slide 3
Abstract Classes (Introduction) Abstract classes define an interface
The implementation is either undefined or partially defined
It's not possible to create an instance of an abstract class
It's only possible to inherit from an abstract class The purpose of abstract classes
Use to create generalized classes Use to force standardized implementations of
derived classes
![Page 4: Programming Pillars](https://reader036.vdocument.in/reader036/viewer/2022083006/56813ddf550346895da7ae3c/html5/thumbnails/4.jpg)
Slide 4
Abstract Classes (Creating) In the abstract class, define the
interface for the class Declare an abstract class or member with
the abstract keyword in the class declaration
![Page 5: Programming Pillars](https://reader036.vdocument.in/reader036/viewer/2022083006/56813ddf550346895da7ae3c/html5/thumbnails/5.jpg)
Slide 5
Abstract Classes (Using) Define the implementation in the
derived class A derived class can inherit from an
abstract classA derived class must implement all abstract members
(those declared as abstract) A derived class can inherit members
implemented in the abstract class
![Page 6: Programming Pillars](https://reader036.vdocument.in/reader036/viewer/2022083006/56813ddf550346895da7ae3c/html5/thumbnails/6.jpg)
Slide 6
Abstract Classes (Example 1) Cryptography uses standard algorithms
to encrypt and decrypt messages There are different cryptographic
algorithms DES, RC2, Rijndael, TripleDES They all “work” the same way
They are all symmetric algorithms The SymmetricAlgorithm class is the
abstract class for all symmetric cryptographic algorithms
![Page 7: Programming Pillars](https://reader036.vdocument.in/reader036/viewer/2022083006/56813ddf550346895da7ae3c/html5/thumbnails/7.jpg)
Slide 7
Abstract Classes (Example 1)
![Page 8: Programming Pillars](https://reader036.vdocument.in/reader036/viewer/2022083006/56813ddf550346895da7ae3c/html5/thumbnails/8.jpg)
Slide 8
Abstract Classes (Example 2) Declare an abstract class named person
public abstract class Person
{}
Declare an abstract method namedpublic abstract bool
SetID(int argID);
Note that the method has NO implementation
![Page 9: Programming Pillars](https://reader036.vdocument.in/reader036/viewer/2022083006/56813ddf550346895da7ae3c/html5/thumbnails/9.jpg)
Slide 9
Implementing an Abstract Method (Example) Use the override keyword to declare
the implementation of an abstract method
public override bool SetID(
int argID)
{
RNumberHidden = argID;
}
![Page 10: Programming Pillars](https://reader036.vdocument.in/reader036/viewer/2022083006/56813ddf550346895da7ae3c/html5/thumbnails/10.jpg)
Slide 10
Prohibiting Inheritance A sealed class is a class that cannot be
inherited Declare sealed classes with the sealed
keyword The string class is not inheritable