Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Object-oriented Programming

Similar presentations


Presentation on theme: "Introduction to Object-oriented Programming"— Presentation transcript:

1 Introduction to Object-oriented Programming

2 Introduction Classes and class relationships are defined using UML Class diagrams These classes must be implemented Any OOP language can be used Visual Basic C# Java C++

3 Key Terms (Programming Object)
Programming objects are designed to mimic real-world objects Television set / DVD Objects have two important characteristics State: Current data about the object A dog has a name, color, etc… Behavior: Things the object can do A dog can bark, fetch, sit, etc.., The text boxes and buttons with which you are familiar are programming objects

4 Key Terms (Class) A class is a template or building block for an object We say that an object is an instance of a class We create several bicycles from the same template

5 Key Terms (Inheritance)
Some classes have share characteristics with other classes Mountain bikes, road bikes, etc… all have shared characteristics OOP allows us to inherit state and behavior from other classes The parent classes is called the superclass The derived class is called the subclass

6 Key Terms (Interface) Here, we are not referring to user interface
We refer to the methods and properties of a class that are exposed to the outside world In its most common form, an interface is a group of related methods with empty bodies Classes can then implement an interface

7 Key Terms (Package) A package is a namespace that organizes a set of related classes and interfaces The Java platform itself is made up of many different packages that you can use In fact, Android uses its own set of Java packages

8 Benefits of OOP Modularity: Objects are generally independent of other objects Information hiding: The internal implementation of an object is hidden from the outside world Implementation vs. interface Code re-use: Objects can be reused by many other programs

9 Declaring a Class Classes are declared inside of a class block
Properties and methods appear inside of the class block

10 Declaring a Class (Example 1)
Declare a class named Bicycle class Bicyle { }

11 Access Modifiers (public)
public members are globally accessible and available to other assemblies (components) Globally available within the component too Note that Intellisense technology will display exposed members Members of the .NET Framework class library are public for example

12 Access Modifiers (private)
private members are part of the implementation They are exposed only to the class containing the declaration Private members are not visible to other components Private members are not visible to other classes

13 Access Modifiers (protected)
Protected members can only be accessed from their own package

14 Declaring a Method (Introduction)
Remember that methods perform an action In C#, methods are nothing more than procedures These are the same procedures that you have used before

15 Declaring a Method (Example)
Create a method named Area public class Circle { public double Area(double argRadius) return 3.14 * radius * radius; }

16 Constructors (Introduction)
A constructor is a procedure having the same name as the class The declaration looks like a method but has no return type Constructors may accept 0 or more arguments For example, the StreamReader constructor accepts a file name as its argument The constructor executes automatically when the developer creates a class instance A constructor is never called directly

17 Constructor (Example)
Create a constructor to increment an instance counter public Circle() { CallCount++; }

18 Static Members (Introduction)
By default, members are instance members One instance exists for each class instance Think of a TextBox. One instance of the Text property exists for each control instance static members belong to the type so one copy exists for all class instances Declare shared members with the static keyword

19 Static Members (1) You need not create a class instance to reference a static member The members of the System.Math class are static, for example Only one data copy of static members exist regardless of the instance count Include the static keyword in variable or procedure declarations

20 Why? Static Members (2) Shared members cannot operate on instance data
Instance members can operate with shared data Why?


Download ppt "Introduction to Object-oriented Programming"

Similar presentations


Ads by Google