Professional Documents
Culture Documents
Objectives
Understand how derived classes inherit from base classes Explore how to add and modify members in derived classes Learn to control how derived classes inherit from base classes Understand how to create and use interfaces Explore techniques for organizing your classes
Agenda
Inheritance Interfaces Organizing Classes
Inheritance
Inefficient to have similar classes with the same members Create a more generic (base) class and then inherit (derive) from the generic class Derived classes inherit the members of the base class Inheritance defines an is-a relationship
A corporation is a customer An individual is a customer
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
Inheritance Hierarchy
Customer is the base class and is the most generic representation of a customer Corporation and Individual are derived classes, inheriting from the base class
Interfaces
Define a set of properties and methods that a class will implement Contain no implementation code A class must implement all members defined in an interface
Visual Studio adds member declarations automatically, you add code to implement members You can override and overload interface members
Implementing an Interface
A class must implement all members defined in an interface
Visual Studio adds member declarations automatically, you add code to implement members You can override and overload interface members
Class can implement multiple interfaces but can only derive from one class Use interfaces to implement smaller sets of members and to enable classes to implement only interfaces they need
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
Organizing Classes
Classes are a good way to organize your code You can also organize your classes
Partial Classes
Helpful on teams where you are writing some class methods and other developers are writing the rest Split the class definition across multiple files Compiler combines the partial classes into one class Calling class uses class the same whether it is made up of partial classes or not
Nested Classes
Class defined within another class Organize class members so they are easier to use at runtime Group members of Customer class
Customer.Information
o
Customer.Financial
o
Customer.Sales
o
RecordSales
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
Namespaces
A way to organize related classes into groups
System.Data contains classes to work with data once you have retrieved it from a data source
Namespaces
By default, the application namespace is the name of the project You can change this in Project Designer Create your own namespaces to organize classes in class libraries
Learn More!
This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details! Learn more on SlideShare
Object-Oriented JavaScript