Encapsulation:Each object includes all the information required for its own operations, and does not rely on other objects to complete its own operations. Such methods and attributes are implemented through class instances.
Benefits: good encapsulation can reduce coupling; the class can be freely modified inside; the class has clear external interfaces.
Inheritance:The relationship of the IS-A. A is-a B: A is B, and a can inherit B. A is a special c
First we want to create an object that we can use to create objects using JavaScript's grammatical features and the idea of classes.One: Package(1) The original method, the code is as follows(2) Factory processing, the code is as follows(3) constructor mode, the code is as follows(4) Prototype method, code as follows(5) Mixed constructor/prototype mode, code as followsTwo: Inheritance (mainly including inheritance of attributes and inheritance of methods)The code is as followsOriginal address: h
form a closure on an object's properties?function A () {var i=0;Function B () {alert (i++);}return b;}A ();//This time in-memory I space is processed by GCvar c=a ();//This usage, GC does not treat I as garbagec (); Output 0C () Output 1, which proves that the variable is closedSystemInner classObject,array/math/boolean/string/regexp/data/numberExampleMath, Static classAlert (Math.Abs (-29))Show current date, dynamic classvar not1=new Date ();Alert (not1.tolocaledatestring ())JavaScript (JS) Fo
) relationship, we say that the subclass Isa parent class, that is, the subclass is a parent class, such as the dog class inherits the animal class, then we say the dog Isa animal, namely the dog is an animal. In the case of vehicles inheriting vehicles, they say that the vehicle ISA completion tool, i.e. the car is a means of transport
The rationality of inheritance: quoting a word from "big talk" to describe the succession. "Man is a man who is born with a mother, a demon is born of a de
First create a project, then create an animal Class (Animal), then create a cat class and a dog class, and finally create a human to feed the animals.Animal Inheritance NSObjectAnd cats and dogs inherit animal classes.Human feeding also inherits NSObjectAnimal class//Declaration of Class#import@interfaceAnimal:nsobject-(void) Jiao;-(void) eat;@end//Realization of Class#import "Animal.h"@implementationAnimal-(void) jiao{NSLog (@"called");}-(void) eat{NSLog (@"Eat");}@endCat class#import "Animal.h
unexpected values are handled, and robustness is enhanced Public void SetName(String name) {if(name==NULL)//Make certain information Else This. name = name; } Public int Getage(){returnAge } Public void Setage(intAge) {if(age0|| Age> Max)//Age beyond the range of possible values, make certain tips Else This. Age = Age; }}封装使得我们使用类的时候不关心类的内部实现,只关心它的接口,这和客观世界一样,我们使用某种东西,只关心它的功能,而不关心它是怎么实现的。Inherited:抽象的原则是舍弃事物的特性,提取其共性。如果不考虑事物的特性,那么就不能反映客观世界中的层次关系。所以继承是是在
Packaging:Encapsulation actually uses methods to hide the data of a class, controlling the user's modifications to the class and the extent to which the data is accessed. The appropriate encapsulation makes the code easier to understand and maintain, and also enhances the security of the code.The access modifier has public,private,protected, which is the default of four.The class is encapsulated by private to prevent it from being arbitrarily changed,
Design and Implementation of Electronic menus for IOS development (inheritance, encapsulation, and polymorphism)
//// Main. m // electronic menu // # import
# Import Food. h # import CoolFood. h # import HotFood. h # import MainFood. h # import Drinks. h # import BillBoard. hint main (int argc, const char * argv []) {Food * food = [[Food alloc] init]; [food showInformation: @ braised pork andShowMateri
class method is not running
3. Static function Features:
As with properties, the static method is not polymorphic, regardless of whether compiling or running is referred to the left.
4.instanceof operators:
The preceding is a reference type variable that is followed by a class that determines whether the preceding object is an instance of the following class, and if it returns True, ClassCastException is avoided unless it returns false.
Public interface Animal {
Packaging
The package is best understood. Encapsulation is one of the object-oriented features and is the main feature of object and class concepts.
Encapsulation, which is the encapsulation of objective things into abstract classes, and classes can put their own data and methods only trusted class or object operation, to the untrusted information hiding.
1 cla
Label: Style File SP on size object method pointer inheritanceEncapsulation is to write the implementation of some specific functions in a file and expose the interface to the outside. The caller calls the method through the interface to implement the function, which implements encapsulation.Inheritance means that the subclass inherits all attributes and methods of the parent class, and then adds its own attributes and methods, called inheritance.Polymorphism is a method of the parent class. Whe
Constructor: Used to encapsulate attributes during initialization: safer data inheritance: extracts the same features of different classes into another class and then inherits the class, reference the property and method polymorphism in this class: different classes make different response overloading for the same method: Generally, the method name can be the same, but the return value type or parameter must be different and overwritten: the abstract
color class are declared as follows, and then declare constants that represent red, green, blue, black, and white colors. public class Color { //color class private int value; Color value public color (int red, int green, int blue) //Construct color object in ternary color public color (int RGB) //Construct Color object in ternary color public int getRGB () //returns the RGB value of th
problem:① Perfect The set () method to ensure that the correct date value ( legitimacy )is obtained;② combines the tomorrow () and yestoday () methods into the following daysafter ( ) methods and adds some methods: public int Getweek ()// returns the day of the week for the current date, ranging from 0to6public string toweekstring ()// returns the Chinese string for the day of the week for the current datePublic b Oolean before (mydate D)// determine whether before the specified date public int
after the addition of two objects, overloads public void Subtract (Complex c) //Two object subtraction, changing the current object public static Complex subtract ( Complex C1, Complex C2) //Returns the object after subtracting two objects, overloads public Boolean equals (Object obj) //Compares two objects for equality}Code implementation:Import Java.util.*;class complexnumber{int really,virtual;public ComplexNumber (int a,int b) {This.set (A/b)
parent;
int c;
} child;
3. Polymorphism
This feature is probably the most useful in object-oriented thinking.
It takes a little bit of skill to implement this feature in C, but it's not impossible.
We use the two structural bodies defined above as parent, child. A simple description of a polymorphic example.
[CPP] View Plain copy print? Voidprint_parent (parent*this) { printf ("a= %d.b=%d.\n ", NBSP;NBSP;THIS-GT;A,NBSP;THIS-GT;B);} voidprin
Polymorphism)
Literally, the behavior of the same method varies with the context.
Wikipedia: Polymorphism (computer science), The ability incomputer programming to present the same interface for differing underlyingforms (data types ).
1,Function Polymorphism(Function polymorphism): that is, function overload)
650) Th
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.