Bài giảng C# 2010 - Chapter 5: Object Oriented Programming

Methods with identical names have different implementations

The Select method is different for radio buttons, check boxes, and list boxes

Allows a single class to have more than one method with different argument lists

 

pptx21 trang | Chuyên mục: Visual C# | Chia sẻ: dkS00TYs | Lượt xem: 1675 | Lượt tải: 5download
Tóm tắt nội dung Bài giảng C# 2010 - Chapter 5: Object Oriented Programming, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level 13/05/2013 ‹#› Abstraction Encapsulation Inheritance Polymorphism Abstraction Characteristics Properties Behaviors  Methods Object Encapsulation Characteristics Properties Behaviors  Methods Package Encapsulation private protected public Inheritance The ability to create a new class from an existing class The existing class is called the base, superclass, or parent The inherited class is called the derived, subclass, or child A derived class has an “is a” relationship with its base class Inheritance Inheritance Inheritance supports reusability Reusability – creation of object functionality that may be used in multiple projects Polymorphism Methods with identical names have different implementations The Select method is different for radio buttons, check boxes, and list boxes Allows a single class to have more than one method with different argument lists How to create Class Class Name Attributes Properties Methods Constructors Attributes Properties public abstract class CAbstractProduct { private string m_strID; private string m_strName; private string m_strDescription; public CAbstractProduct() { } public string ID { get { return this.m_strID; } set { this.m_strID = value; } } public string Name { get { return this.m_strName; } set { this.m_strName = value; } } public string Description { get { return this.m_strDescription; } set { this.m_strDescription = value; } } public abstract void doSomething(); } Methods Constructor public class CProduct : CAbstractProduct { private double m_dPrice; public CProduct() { } public double Price { get { return this.m_dPrice; } set { this.m_dPrice = value; } } public override void doSomething() { throw new NotImplementedException(); } } public class CBook:CProduct { private string m_strISBN; private string m_strAuthor; private string m_strTitle; public CBook() { } public string ISBN { get { return this.m_strISBN; } set { this.m_strISBN = value; } } public string Author { get { return this.m_strAuthor; } set { this.m_strAuthor = value; } } public string Title { get { return this.m_strTitle; } set { this.m_strTitle = value; } } } public class CCompactDisc:CProduct { private string m_strArtist; private string m_strTitle; public CCompactDisc() { } public string Artist { get { return this.m_strArtist; } set { this.m_strArtist = value; } } public string Title { get { return this.m_strTitle; } set { this.m_strTitle = value; } } public override void doSomething() { throw new NotImplementedException(); } } public class CTravelGuide:CBook { private string m_strCountry; public CTravelGuide() { } 	 public string Country { get { return this.m_strCountry; } set { this.m_strCountry = value; } } }  Garbage Collection Operator new allocates memory When objects are no longer referenced, the CLR performs garbage collection Garbage collection helps avoid memory leaks (running out of memory because unused memory has not been reclaimed) Allocation and deallocation of other resources (database connections, file access, etc.) must be explicitly handled by programmers Use finalizers in conjunction with the garbage collector to release resources and memory Before garbage collector reclaims an object’s memory, it calls the object’s finalizer Each class has only one finalizer (also called destructor) Name of a destructor is the ~ character, followed by the class name Destructors do not receive any arguments public class CTravelGuide:CBook { private string m_strCountry; public CTravelGuide() { } public string Country { get { return this.m_strCountry; } set { this.m_strCountry = value; } } ~CTravelGuide() { Console.WriteLine("deconstructor"); } } END 

File đính kèm:

  • pptxBài giảng C# 2010 - Chapter 5 Object Oriented Programming.pptx
Tài liệu liên quan