190 likes | 467 Views
OOP. Abstraction Classes Class Members: Properties & Methods Instance (object ) Encapsulation Interfaces Inheritance Composition Polymorphism Using Inheritance Using Interfaces. Abstraction.
E N D
OOP • Abstraction • Classes • Class Members: Properties & Methods • Instance (object) • Encapsulation • Interfaces • Inheritance • Composition • Polymorphism • Using Inheritance • Using Interfaces
Abstraction A model of the properties, actions, and interactions of real world objects that are required for a software application.
Classes A class is a template for an object. The class defines the properties (data attributes) and methods (functions in a class) that will be common to all instances of that class (objects) created from it.
Encapsulation Functional details (how a member is implemented) of one object are hidden from objects that interact with it.
Classes & Interfaces An Interface is a logical group of properties & methods that can be implemented by a class • All Interface members are implicitly public • There is no code inside interface members. • Can’t be static, virtual, abstract, or sealed
Interfaces & ArcGIS Once published, Interfaces should not be modified (add/remove members) (e.g. IBasicMap, IBasicMap2)
Inheritance • Some classes have some things in common • The common things can be promoted to a base class • The specific things can remain in the derived classes
Inheritance syntax and keywords • MyClass : BaseClass • MyClass inherits from BaseClass, e.g.:<none | internal | public> class Cow : Animal • abstract keyword • Class cannot be instantiated only derived from, e.g.:public abstract class Animal • sealed keyword • Class cannot be derived from, e.g.:public sealed class Cow
Inheritance syntax and keywords virtual & override keywords • Base class virtual members can be overridden in derived classes
Inheritance syntax and keywords protected keyword • Member is accessible to base class and derived classes NOT to external classes
Inheritance syntax and keywords base keyword • Call members on base class
Scope Review public internal (default) protected Entire solution private More … Assembly only More … Derived classes More … Class only More …
Inheritance and casting Casting = converting between types explicit implicit • Can also cast between interfaces on • Same class • Base and derived classes
Abstract Classes vs Interfaces Similarities • Can be • Inherited • SomeClass : BaseClass • ISomeInterface : ISomeOtherInterface • Declared as variable types • BaseClass bc; • ISomeInterface si; • Cannot be instantiated • new BaseClass() • new ISomeInterface()
Abstract Classes vs Interfaces Differences
Layer FeatureLayer RasterLayer Map Composition One class composed of another No direct access to Udder via Cow Composition in ArcGIS * Composition can be setup to allow access to members of dependent classes.
Polymorphism (Using Inheritance) Polymorphism: Members that have the same name but different implementations in different objects Polymorphism using inheritance: Members in derived classes have same name but different implementations than the base class.
Polymorphism (Using Interfaces) Implementation of interface can be different in classes that implement it
OOP • Abstraction • Classes • Class Members: Properties & Methods • Instance (object) • Encapsulation • Interfaces • Inheritance • Composition • Polymorphism • Using Inheritance • Using Interfaces