当前位置:网站首页>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;边栏推荐
- Leetcode51.n queen
- Day05 錶格
- false sharing
- 2022 examination summary of quality controller - Equipment direction - general basis (quality controller) and examination questions and analysis of quality controller - Equipment direction - general b
- 查詢效率提昇10倍!3種優化方案,幫你解决MySQL深分頁問題
- If you have just joined a new company, don't be fired because of your mistakes
- Setting methods, usage methods and common usage scenarios of environment variables in postman
- 2022 Guangxi provincial safety officer a certificate examination materials and Guangxi provincial safety officer a certificate simulation test questions
- Li Chuang EDA learning notes 13: electrical network for drawing schematic diagram
- PTA tiantisai l1-079 tiantisai's kindness (20 points) detailed explanation
猜你喜欢

The first spring of the new year | a full set of property management application templates are presented, and Bi construction is "out of the box"

WordPress collection WordPress hang up collection plug-in
![[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush](/img/94/2bdc31ec05595dbbc8a7a8d6b22252.jpg)
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush

GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day

Webhook triggers Jenkins for sonar detection
![Backpropagation formula derivation [Li Hongyi deep learning version]](/img/ef/f76eae39c4f8716a0030a60c85b09c.gif)
Backpropagation formula derivation [Li Hongyi deep learning version]

Solve the problem that the tabbar navigation at the bottom of vantui does not correspond to the page (window.loading.hash)

Li Chuang EDA learning notes 13: electrical network for drawing schematic diagram

National standard gb28181 protocol platform easygbs fails to start after replacing MySQL database. How to deal with it?

Zblog collection plug-in does not need authorization to stay away from the cracked version of zblog
随机推荐
Basé sur... Netcore Development blog Project Starblog - (14) Implementation of theme switching function
Contest3145 - the 37th game of 2021 freshman individual training match_ D: Ranking
New year's first race, submit bug reward more!
Code Execution Vulnerability - no alphanumeric rce create_ function()
Résumé: entropie, énergie libre, symétrie et dynamique dans le cerveau
Contest3145 - the 37th game of 2021 freshman individual training match_ G: Score
Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
Jenkins configures IP address access
Redis notes (I) Linux installation process of redis
Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
National standard gb28181 protocol platform easygbs fails to start after replacing MySQL database. How to deal with it?
Solve the problems encountered by the laravel framework using mongodb
Rhcsa day 3
There is no need to authorize the automatic dream weaving collection plug-in for dream weaving collection
Want to do something in production? Then try these redis commands
[database I] database overview, common commands, view the table structure of 'demo data', simple query, condition query, sorting data, data processing function (single row processing function), groupi
Record a problem that soft deletion fails due to warehouse level error
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
Leetcode51.n queen
How to pipe several commands in Go?