Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I f in my code that reused only by me
I declare everything public.

what risk I will encounter in my code.

can someone please give me an example of a risk.

and second question.

what is the difference between
richtextbox.clear()
and
richtextbox.text = ""

thank you.

What I have tried:

public class p123456
public x as integer
end class
Posted
Updated 21-Apr-20 22:10pm

It is good practice not to make everything public in a class. It may be OK for personal applications, but it could be important later if you are developing commercial programs. Good discipline at any stage is always worthwhile.

As to your other question, it is all explained in the documentation: RichTextBox Class (System.Windows.Forms) | Microsoft Docs[^].
 
Share this answer
 
Classes and their field, properties, methods, delegate, and events should not all be public: some of the information should be on a "need to know" basis only. Why? Well you drive a car with public information on it: Make, model, colour, registration number. That's all important, but it's not the only information: your name as the owner, your address, your driving licence status, conviction history are all available to law enforcement but aren't (except in Switzerland) accessible to the general public.
So if you cut someone up / off they have your public information - registration number, make, model, colour - so they can report the problem to the police, but they can;t turn up on your doorstep with a baseball bat.
Private information is internal to the class, it's what the class needs to know in order to work. generally speaking, all fields, all Controls, should be Private (or at least not Public)
Public information is what the rest of the world needs to know in order to use the class.

If you expose private information to the outside world, then that restricts what you can do with the class - because the outside world my use that private data to do something you didn't intend and your changes to the class may break external code: so you need to think very, very carefully before you can alter the way your class works internally.

Have qa look here: Understanding Access Modifiers in VB.NET | BinaryIntellect Knowledge Base[^]
 
Share this answer
 
Comments
Member 13569650 22-Apr-20 4:48am    
of course if you're app deals with
personal data you use password
to protect personal data.

consider a calculation part of any app all data for calculation can be public.
the classed become simple
no need for get and set and other things like that.

I know the discipline to declare private as possible.
and I seen books that declare
as private things that can be public.

I think outside data that must be
secret like account number
bank account , and other people personal data that every app
protect by password
there no need to complicate the
classes for that.

I am not against discipline.
and I think I will use the books
recommendations.

but it's absolutely not required.

thank you very much.
Member 13569650 22-Apr-20 5:12am    
consider a regular expression tester application.

what is the need for private declaration.
OriginalGriff 22-Apr-20 5:27am    
To separate "how it works" from "what it does". It needs public input (the regex, regex options, the test string) and it provides public output (the results).
But all the internals of how it actually tests the regex are off limits to teh calling class as it doesn't need to know.
Member 13569650 22-Apr-20 5:40am    
yes you right.
that good discipline.

but if all declared public
there is no risk.

that the point here.
OriginalGriff 22-Apr-20 5:53am    
Depends what you define as "risk". I include "liable to cause me problems in the future" as a risk factor - I don't want to make my life more difficult.
If you are happy with making work for yourself in a couple of months time that you didn't need to, and facing derision if anyone sees your code (such as a code review) then it's "not a risk".

Your choice!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900