轉貼:4 major principles of Object-Oriented Programming
Encapsulation
Accessor - An accessor is a method that is used to ask an object about itself. In
OOP, these are usually in the form of properties, which have, under
normal conditions, a get method, which is an accessor method.
Mutator - Mutators are public methods that are used to modify
the state of an object, while hiding the implementation of exactly how
the data gets modified.
Abstraction
data abstraction is nothing more than the implementation of
an object that contains the same essential properties and actions we
can find in the original object we are representing.
Inheritance
Objects can relate to eachotherwith either a “has a”, “uses a” or an “is a” relationship.
For example, LibraryAsset is a superclass, or base class, and that maintains
only the data and methods that are common to all loanable assets.
Book, magazine, audiocassette and microfilm will all be subclasses or derived classes
or the LibraryAsset class, and so they inherit these
characteristics. The inheritance relationship is called the “is
a” relationship.
Polymorphism
Polymorphism means one name, many forms. Polymorphism
manifests itself by having multiple methods all with the same name, but
slighty different functionality.
There are 2 basic types of polymorphism. Overridding, also
called run-time polymorphism, and overloading, which is referred to as
compile-time polymorphism.
overriding : 字類別的方法蓋掉父類別的方法。
overloading : 同樣的方法名稱,但因帶的參數不同,而呼叫不同的方法內容。
沒有留言:
張貼留言