1 / 10

Programming Pillars

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

lilka
Download Presentation

Programming Pillars

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Pillars Inheritance Part 2

  2. Lecture Overview • Abstract classes

  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

  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

  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

  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

  7. Abstract Classes (Example 1)

  8. Abstract Classes (Example 2) • Declare an abstract class named person public abstract class Person {} • Declare an abstract method named public abstract bool SetID(intargID); • Note that the method has NO implementation

  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; }

  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

More Related