CSE459_CSharp_03_ClassesStructs

CSE459_CSharp_03_ClassesStructs - Programming in C#...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Programming in C# Object-Oriented Object-Oriented CSE 459.24 Prof. Roger Crawfis
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Key Object-Oriented Concepts Objects, instances and classes Identity Every instance has a unique identity, regardless of its data Encapsulation Data and function are packaged together Information hiding An object is an abstraction User should NOT know implementation details
Background image of page 2
Key Object-Oriented Concepts Interfaces A well-defined contract A set of function members Types An object has a type, which specifies its interfaces and their implementations Inheritance Types are arranged in a hierarchy Base/derived, superclass/subclass Interface vs. implementation inheritance
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Key Object-Oriented Concepts Polymorphism The ability to use an object without knowing its precise type Three main kinds of polymorphism Inheritance Interfaces Reflection Dependencies For reuse and to facilitate development, systems should be loosely coupled Dependencies should be minimized
Background image of page 4
Programming in C# Object-Oriented Object-Oriented CSE 459.24 Prof. Roger Crawfis
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Programming in C# Interfaces Interfaces CSE 459.24 Prof. Roger Crawfis
Background image of page 6
Interfaces An interface defines a contract An interface is a type Contain definitions for methods, properties, indexers, and/or events Any class or struct implementing an interface must support all parts of the contract Interfaces provide no implementation When a class or struct implements an interface it must provide the implementations
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Interfaces Interfaces provide polymorphism Many classes and structs may implement a particular interface. Hence, can use an instance of any one of these to satisfy a contract. Interfaces may be implemented either: Implicitly – contain methods with the same signature. The most common approach. Explicitly – contain methods that are explicitly labeled to handle the contract.
Background image of page 8
public interface IDelete {   void Delete(); } public class TextBox : IDelete {   public void Delete() { . .. } } public class Car : IDelete { } TextBox tb = new  TextBox(); tb.Delete(); Car c = new Car(); iDel = c; iDel.Delete(); Interfaces Example
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Explicit Interfaces Explicit interfaces require the user of the class to explicitly indicate that it wants to use the contract. Note: Most books seem to describe this as a namespace conflict solution problem. If that is the problem you have an extremely poor software design. The differences and when you want to use them are more subtle.
Background image of page 10
Explicit Interfaces namespace OhioState.CSE494R.InterfaceTest { public interface IDelete { void Delete(); } public class TextBox : IDelete { # region IDelete Members void IDelete.Delete() { . .. } # endregion } } TextBox tb = new  TextBox(); tb.Delete();   // compile  error iDel = tb; iDel.Delete();
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Explicit Interfaces The ReadOnlyCollection<T> class is a good example of using an explicit interface implementation to hide the methods of the IList<T> interface that allow modifications to the collection.
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/27/2012 for the course CSE 459.24 taught by Professor Crawfis during the Winter '11 term at Ohio State.

Page1 / 64

CSE459_CSharp_03_ClassesStructs - Programming in C#...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online