Java's thinking about objects __java

Source: Internet
Author: User
Tags modifier variable scope
Immutable Objects and classes

immutable classes need to meet the conditions:
-All data fields are private
-Methods without a modifier
-without an accessor, it will return a carton variable data field reference variable scope class variable/data field
instance variables and static variable local variables for a class
Variables defined internally by methods

If a local variable has the same name as a class variable, then the local variable takes precedence, and the class variable with the same name is hidden. This reference

keywordthis: refers to the reference name of the calling object itself. A common use is to reference the hidden data fields of a class. abstraction and encapsulation of classes

Class Abstraction
Detach the implementation and use of a class. The creator of the class provides a description of the class, letting the user know how to use the class. All of the methods and data fields that can be accessed from outside the class, as well as descriptions of how they are expected to act, are collectively referred to as contracts for that category.

Encapsulation of a class
The details of the implementation are encapsulated and hidden from the user. the design principle cohesion of the class
A class should describe a single entity, and all class operations should logically work together to support a coherent goal. Consistency
Follow standard Java program design style and naming conventions. Encapsulation of
A class should use the private modifier to hide its data, so that it is easy to maintain, so that the user can access it directly. Clarity of
Class should have a clear contract that is easy to interpret and understand. Integrity
In order to be used in a wide range of applications, a class should provide a variety of scenarios through properties and methods to suit the different needs of the user. instance and static
A variable or method that relies on a specific instance of a class should be an instance variable or method, and if a variable is shared by all instances of the class, it should be declared static.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.