Object-Oriented Programming - PowerPoint PPT Presentation

About This Presentation
Title:

Object-Oriented Programming

Description:

... DoWork() { } } Allocation/Deallocation: C# employs automatic memory management, which frees developers from manually allocating and freeing the memory occupied ... – PowerPoint PPT presentation

Number of Views:14
Avg rating:3.0/5.0
Slides: 8
Provided by: Ryan1393
Category:

less

Transcript and Presenter's Notes

Title: Object-Oriented Programming


1
Object-Oriented Programming
  • C -- Ryan Graczyk

2
Introduction
  • Classification of C according to its support of
    Object-Orientation
  • C and Java are programming languages that were
    designed to support object-oriented programming
    and do not support other programming paradigms,
    but still employ some of the basic imperative
    structures. among such languages. Smalltalk is
    the only pure object-oriented language.

3
Single Inheritance
  • Classes can inherit from another class. This is
    accomplished by putting a colon after the class
    name when declaring the class, and naming the
    class to inherit fromthe base classafter the
    colon
  • public class A
  • public A()
  • public class B A
  • public B()
  • The new classthe derived classthen gains all
    the non-private data and behavior of the base
    class in addition to any other data or behaviors
    it defines for itself.
  • Class B is effectively both B and A. When you
    access a B object, you can use the cast operation
    to convert it to an A object. The B object is not
    changed by the cast, but your view of the B
    object becomes restricted to A's data and
    behaviors. After casting a B to an A, that A can
    be cast back to a B. Not all instances of A can
    be cast to Bjust those that are actually
    instances of B. If you access class B as a B
    type, you get both the class A and class B data
    and behaviors. The ability for an object to
    represent more than one type is called
    polymorphism.

4
Multiple Inheritance
  • Multiple (Implementation) Inheritance is not
    supported in C.
  • Multiple Interface Inheritance is supported and
    can replace Multiple implementation inheritance
    in most cases.

5
Dynamic Binding
  • C 4.0 introduces a new static type
    called dynamic. When you have an object of
    type dynamic you can do things to it that are
    resolved only at runtime
  • dynamic d  GetDynamicObject(...)
  • d.M(7)
  • The C compiler allows you to call a method with
    any name and any arguments on d because it is of
    type dynamic. At runtime the actual object
    that d refers to will be examined to determine
    what it means to call M with an int on it.
  • The type dynamic can be thought of as a special
    version of the type object, which signals that
    the object can be used dynamically. It is easy to
    opt in or out of dynamic behavior any object can
    be implicitly converted to dynamic. Conversely,
    expressions of type dynamic can be implicitly
    converted to object, or indeed any other type, as
    long as there exists a conversion at run time
  • dynamic d  7 // compile-time implicit conversion
  • int i  d     // runtime implicit conversion
  • Classes use the virtual keyword for base and
    override for derived classes.

6
Design Issues for OO
  • C is Statically type-checked unless otherwise
    defined (using the dynamic keyword).
  • dynamic local Local variable // a dynamic
    local variable
  • Polymorphism
  • public class BaseClass
  • public virtual void DoWork()
  • public class DerivedClass BaseClass
  • public override void DoWork()
  • Allocation/Deallocation
  • C employs automatic memory management, which
    frees developers from manually allocating and
    freeing the memory occupied by objects. Automatic
    memory management policies are implemented by a
    garbage collector.

7
Summary
  • General Characteristics
  • C includes both classes and structs.
  • Inheritance
  • The following is C syntax for defining classes
  • public class NewClass ParentClass
  • Nested Classes
  • C supports static nested classes that are
    directly nested in a class.
  • Evaluation
  • Since C is based on its predecessors (C
    Java), from which designers learnt and improved,
    it is expected that some of the problems are
    remedied.
Write a Comment
User Comments (0)
About PowerShow.com