Object-oriented features:
- Encapsulation: Even if the data structure inside the object changes, as long as the public to the external method name, function does not change, the user will be used as usual, such as we go to call the time class method.
- Polymorphic: Each object of the object class, String class, and float class calls the To_s method, resulting in a different result.
Multi-state Thinking method----Duck model
"You can walk like a duck, you can crow like a duck, it must be a duck", the behavior of the object (walking, crows are like ducks), then whether or not the real ducks treat it as a duck. Examples are as follows:
Fetch_and_downcase only requires (can get elements in the form of Ary[index], the obtained elements can execute the Downcase method), so as long as there are these behaviors, whether arrays or hashes, this is the duck model.
Object-oriented examples:
Conceptual and network Knowledge Supplement:
System----refers to the type of communication protocol used
Connect to the server on the network----need to know the hostname and port number of the server, the following Ruby official website hostname is www.ruby-lang.org (just like 127.0.0.1, except it is not local debugging, provide external access to the domain name), the port number is 80.
Path----When a server is found through the hostname and port, to access a specific file, the path is also required to locate the resource on the server
At this stage we just need to know that the URL is one of the URIs.
Get the HTML from the homepage of the Ruby website and output it to the console example:
Focus on the fifth line call Net::http #get方法的时候, the specific process:
- Use the host name and port number to establish communication with the server (called socket, socket, with host name and port number)
② use the path to create a Net::httprequest object that represents the request information
- Request information for Socket write
④ reads the data from the socket and saves it to the Net::httpresponse object that represents the response information
- Use the functionality provided by the Net::httpresponse itself to parse the response information, extract the part of the document and return it.
The flowchart is as follows:
The eighth chapter of object-oriented instance complements