Click here to Skip to main content
15,499,430 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Another code for thought: public members Pin
CPallini30-Oct-18 2:41
mveCPallini30-Oct-18 2:41 
GeneralRe: Another code for thought: public members Pin
Super Lloyd30-Oct-18 2:53
MemberSuper Lloyd30-Oct-18 2:53 
GeneralRe: Another code for thought: public members Pin
Pete O'Hanlon30-Oct-18 2:14
mvaPete O'Hanlon30-Oct-18 2:14 
GeneralRe: Another code for thought: public members Pin
Super Lloyd30-Oct-18 2:19
MemberSuper Lloyd30-Oct-18 2:19 
GeneralRe: Another code for thought: public members Pin
Eric Lynch30-Oct-18 3:30
MemberEric Lynch30-Oct-18 3:30 
GeneralRe: Another code for thought: public members Pin
Marc Clifton30-Oct-18 3:39
mvaMarc Clifton30-Oct-18 3:39 
GeneralRe: Another code for thought: public members Pin
RandyBuchholz30-Oct-18 5:56
MemberRandyBuchholz30-Oct-18 5:56 
GeneralRe: Another code for thought: public members Pin
RandyBuchholz30-Oct-18 5:04
MemberRandyBuchholz30-Oct-18 5:04 
When I first leaned OO (early 80's), the general school of thought was behavior before structure. It was almost a functional approach, in that you defined a small set of public "action" methods that essentially defined the object. Exposing data (including using simple set;set;) was generally frowned on. Data belonged in structures. Back then though, Structures were basically classes without methods. The idea was that data represents state, and you should only change state through actions, not directly. These days things are different (e.g., in many languages Structures can have methods, and the difference is usually stack v heap), and we have been living in a Data-Driven world, so for many, classes have become collections of data properties (e.g., Models).

I still keep the structure v behavior mindset, and generally (though not formally) divide my classes into those camps. If a class is structural, it will have a lot of public stuff, so you can easily manipulate the structure. If it is behavioral, only the actions that define it through its capabilities are public. Think of a Stoplight class. It has three (bool) lights - Red, Yellow, and Green. A "public" data-driven mindset might expose these as three public properties. A user could turn on Red and Green at the same time though. You make the user do more work to use your class. A behavioral mindset would expose a single public property (or method). light.Flow = GO, light.Flow = Stop. (Ignoring things like flashing Yellow). The Yellow state between Go and Stop is internal, and not exposed directly, but through a protected/internal "yellowDuration" accessor. Extend this to an intersection. It could encapsulate four stoplights, and expose a single public property - Allow: Allow = Direction.NorthSouth, Allow = Direction.EastWest, Allow = Direction.None. By inspecting the public methods/properties, it is clear what this does. It makes the class easy to use, and it protects conditions. A "public" mindset might expose 12 individual lights on Intersection - is it clear what this class does by inspecting the public properties? What is the value of exposing everything (YAGNI). And what prevents (without extra coding) all lights being Green?

Utility classes are a another thing all together. They are less classes than collections of methods. (i.e., they have no self-identity).

Encapsulation and data-hiding are a core foundation of OO concepts. Public/Private are key to both. If you want to make everything public, why not just make everything static global while you are at it? Smile | :)
GeneralRe: Another code for thought: public members Pin
David Crow30-Oct-18 5:17
MemberDavid Crow30-Oct-18 5:17 
GeneralRe: Another code for thought: public members Pin
patbob30-Oct-18 7:01
Memberpatbob30-Oct-18 7:01 
GeneralRe: Another code for thought: public members Pin
Gary Wheeler30-Oct-18 7:03
MemberGary Wheeler30-Oct-18 7:03 
GeneralRe: Another code for thought: public members Pin
Mark_Wallace30-Oct-18 23:28
MemberMark_Wallace30-Oct-18 23:28 
GeneralWSO CCC OTD 2018-10-30 Pin
OriginalGriff29-Oct-18 23:57
mveOriginalGriff29-Oct-18 23:57 
AnswerRe: WSO CCC OTD 2018-10-30 Pin
megaadam30-Oct-18 0:15
professionalmegaadam30-Oct-18 0:15 
GeneralRe: WSO CCC OTD 2018-10-30 - We have a winner! Pin
OriginalGriff30-Oct-18 0:18
mveOriginalGriff30-Oct-18 0:18 
GeneralRe: WSO CCC OTD 2018-10-30 Pin
Mark Parity30-Oct-18 0:15
MemberMark Parity30-Oct-18 0:15 
GeneralRe: WSO CCC OTD 2018-10-30 Pin
OriginalGriff30-Oct-18 0:19
mveOriginalGriff30-Oct-18 0:19 
GeneralC# code survey Pin
Super Lloyd29-Oct-18 22:37
MemberSuper Lloyd29-Oct-18 22:37 
GeneralRe: C# code survey Pin
Jacquers29-Oct-18 22:56
MemberJacquers29-Oct-18 22:56 
GeneralRe: C# code survey Pin
#realJSOP30-Oct-18 7:08
mva#realJSOP30-Oct-18 7:08 
GeneralRe: C# code survey Pin
Wastedtalent29-Oct-18 23:04
professionalWastedtalent29-Oct-18 23:04 
GeneralRe: C# code survey Pin
CPallini29-Oct-18 23:06
mveCPallini29-Oct-18 23:06 
GeneralRe: C# code survey Pin
Jörgen Andersson29-Oct-18 23:23
professionalJörgen Andersson29-Oct-18 23:23 
GeneralRe: C# code survey Pin
CPallini29-Oct-18 23:37
mveCPallini29-Oct-18 23:37 
GeneralRe: C# code survey Pin
GuyThiebaut29-Oct-18 23:13
professionalGuyThiebaut29-Oct-18 23:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Straw Poll

When thinking about your job, how important is the option to work from home?
Some bosses are casual about where you work, and some, naming no names, will insist you're in the office, always. What are your thoughts?
  Results   771 votes