In the C# language the interface is a definition of a role a group of abstract actions Interfaces are also known as contracts or specifications of behavior An object can have multiple ro
Trang 1Chương 2
XÂY DỰNG ỨNG ĐA TẦNG
Trang 44
Trang 6Abstraction
Trang 7In the C# language the interface is a definition
of a role (a group of abstract actions)
Interfaces are also known as contracts or
specifications of behavior
An object can have multiple roles (or
implement multiple interfaces/contracts) and its users can utilize it from different points of
view
Abstraction
Trang 8Abstraction
Trang 1111
Trang 13Polymorphism is often referred to as the third pillar
of OOP, after encapsulation and inheritance
Polymorphism is a Greek word that means shaped" and it has two distinct aspects:
"many-At run time, objects of a derived class may be treated as objects of a base class in places
such as method parameters and collections or array
Base classes may define and implement virtual
methods, and derived classes can override
them
Trang 14Polymorphism
Trang 15Polymorphism
Trang 16Polymorphism
Trang 17Polymorphism
Trang 18Polymorphism
Trang 19Kết quả thực thi
Polymorphism
Trang 21Class in C#
Constructor
Properties Attributes
Methods
Trang 22Garbage Collection
Operator new allocates memory
When objects are no longer referenced, the CLR (Common Language Runtime) 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
Trang 23Garbage Collection
Use finalizer 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
Trang 24// Cleanup statements
} finally {
} }
Trang 25Garbage Collection
Trang 26Mô hình 3 tầng