当前位置:网站首页>Package details_ Four access control characters_ Two details of protected
Package details_ Four access control characters_ Two details of protected
2022-07-04 03:19:00 【hv102】
Encapsulation is one of the three characteristics of object-oriented .
The concept of encapsulation :
High cohesion , Low coupling .
The function and meaning of encapsulation :
Our programming should pursue ,“ High cohesion , Low coupling ”. High cohesion means that the internal data operation details of a class are completed by themselves , External interference is not allowed , The second coupling is to expose only a small number of methods to external use , Try to facilitate external calls .
4, The specific advantages of being encapsulated in :
Improve the security of the code
Improve code reusability
“ High cohesion ”: Package details , Easy to modify internal code , Improve maintainability .
“ Low coupling ”: Simplify external calls , Easy for callers to use , Easy to expand and collaborate .
The implementation of encapsulation ---- Use access control
Java It's using “ Access control character ” To control which details need to be encapsulated , What needs to be exposed .
Java in 4 Kind of “ Access control character ” Namely :pritave( Private )\default( Illegal )\protected( The protected )\public( Public ).
【 notes 】 About protected Two details of :
1. If parent and child are in same package , Subclasses can access the parent class protected member , You can also access the of the parent object
protected member
2. If subclass and parent are not in same package , Subclasses can access the parent class protected member , Cannot access parent object
Of protected member
Simple rules encapsulated in development :
- Properties are generally used private Access right .
- After the property is private , Provide corresponding get/set Method to access related properties , These methods are usually public Embellished , To provide assignment and read operations on properties ( Be careful : boolean Variable get The method is is start !)
- Method : Some auxiliary methods only used in this class can be used private modification , I hope the methods called by other classes use public modification .
【 Example 】 JavaBean Packaging demonstration of
public class Person
∥ Properties are generally used private modification
private String name;
private int age;
private boolean flag;
∥ Provide... For properties public Embellished set/get Method
public String getName((
return name;
public void setName(String name){
this.name name;
public int getAge0
return age;
边栏推荐
- Code Execution Vulnerability - no alphanumeric rce create_ function()
- I stepped on a foundation pit today
- Li Chuang EDA learning notes 13: electrical network for drawing schematic diagram
- Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
- static hostname; transient hostname; pretty hostname
- 查詢效率提昇10倍!3種優化方案,幫你解决MySQL深分頁問題
- 96% of the collected traffic is prevented by bubble mart of cloud hosting
- Database concept and installation
- How to use websocket to realize simple chat function in C #
- Remote work guide
猜你喜欢
Li Chuang EDA learning notes IX: layers
Want to do something in production? Then try these redis commands
Pagoda SSL can't be accessed? 443 port occupied? resolvent
Easy to win insert sort
Tsinghua University product: penalty gradient norm improves generalization of deep learning model
Solve the problem that the tabbar navigation at the bottom of vantui does not correspond to the page (window.loading.hash)
Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi
Monitoring - Prometheus introduction
Add token validation in swagger
VRRP+BFD
随机推荐
Unity writes a character controller. The mouse controls the screen to shake and the mouse controls the shooting
Talking about custom conditions and handling errors in MySQL Foundation
National standard gb28181 protocol platform easygbs fails to start after replacing MySQL database. How to deal with it?
Short math guide for latex by Michael downs
2022 attached lifting scaffold worker (special type of construction work) free test questions and attached lifting scaffold worker (special type of construction work) examination papers 2022 attached
2022 examination summary of quality controller - Equipment direction - general basis (quality controller) and examination questions and analysis of quality controller - Equipment direction - general b
Unity knapsack system (code to center and exchange items)
Base d'apprentissage de la machine: sélection de fonctionnalités avec lasso
Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
The "message withdrawal" of a push message push, one click traceless message withdrawal makes the operation no longer difficult
2022 Guangxi provincial safety officer a certificate examination materials and Guangxi provincial safety officer a certificate simulation test questions
Buuctf QR code
Pagoda SSL can't be accessed? 443 port occupied? resolvent
Code Execution Vulnerability - no alphanumeric rce create_ function()
Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine
Fudan released its first review paper on the construction and application of multimodal knowledge atlas, comprehensively describing the existing mmkg technology system and progress
System integration meets the three business needs of enterprises
Want to do something in production? Then try these redis commands
This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
機器學習基礎:用 Lasso 做特征選擇