ByteCode.News
Submit RSS Atom Sign in

Back to the channels

#java

  1. * Betal joined #java
  2. * michele joined #java
  3. * dinomug joined #java
  4. * kcomhnall joined #java
  5. * waz joined #java
  6. * youfoundwaldo joined #java
  7. * waz joined #java
  8. * bdkl joined #java
  9. * bdkl joined #java
  10. * mindCrime joined #java
  11. * pengu1nx joined #java
  12. * geli joined #java
  13. * NeXeN joined #java
  14. * kusanagi joined #java
  15. * bdkl joined #java
  16. * agnivn joined #java
  17. * agnivn joined #java
  18. * Aedil joined #java
  19. * zorone joined #java
  20. * jjakob joined #java
  21. * zorone_ joined #java
  22. * zorone_ joined #java
  23. * yaboishady joined #java
  24. * agnivn joined #java
  25. * rvalue- joined #java
  26. * Muspah joined #java
  27. * ForeverDreaming joined #java
  28. * Nemu64- joined #java
  29. * ferdna joined #java
  30. pengu1nx Why are attributes often private, but then have a getter and setter?
  31. * stfstfm_ joined #java
  32. * yamada joined #java
  33. * MonsterAbyss joined #java
  34. * vincere joined #java
  35. * Aedil joined #java
  36. * MonsterAbyss joined #java
  37. * MonsterAbyss joined #java
  38. * MonsterAbyss joined #java
  39. Swayze a design pattern that emerged out of the need to often validate values before assigning them
  40. Swayze also you can change complex internal logic without changing your classes contract
  41. NeXeN never reach into private members, we all learned that in kindergarten
  42. Swayze hes asking WHY they're private to begin with
  43. Swayze (you CANT reach into private members)
  44. NeXeN but my joke is funnier
  45. * acidjnk joined #java
  46. pengu1nx I don't really understand the second note. What exactly do you mean by contract and why would the attribute being public interfere with changing it?
  47. * polarian joined #java
  48. Bombe pengu1nx, the “contract” of a class is the public API it offers, i.e. all the methods you can use to interact with it.
  49. Bombe If you make fields public, they become part of that contract.
  50. * polarian joined #java
  51. Bombe Which can be fine, mind you, but it does make some things harder: testing involving mocks and public final fields is a mess, and if you want to change how you store certain properties, you now can’t, because every client of your class expects the field to be of type X.
  52. Bombe If you supply an accessor to get to the value of the field, you’re free to change the representation within your class, how it’s stored, how it’s processed, and the accessor can take care of turning it into the X the clients expect.
  53. Bombe That’s also called “encapsulation,” and it’s one of the basic principles of OOP.
  54. nimaje an easy example would be complex numbers, you can represent these in polar coordinates or in cartesian coordinates, if you start with one representation and later notice that the other representation would be better for your use case then you can just change the representation if the fields are not part of the public api and change the rest of the program later if at all
  55. * tomboy64 joined #java
  56. * mindCrime joined #java
  57. dreamreal A simple example: setPronunciation() and getPronunciation(). You might mutate the value on set such that it has an internal tokenization, while getting the value might SIMILARLY annotate the tokenization with whitespace, translation from unicode, whatever. The external value and the internal value representations don't have to be the same.
  58. * stfstfm joined #java
  59. * stfstfm_ joined #java
  60. * jreicher joined #java
  61. * MikeBux joined #java
  62. * stfstfm joined #java
  63. * sponkz joined #java
  64. * stfstfm joined #java
  65. * zorone joined #java
  66. * CodeGeek!~codegeek@about/java/CodeGeek changed the topic to: Welcome! || Read Channel Rules at https://javachannel.org/ before participating. || Paste limit is two lines; ~pastebin lists options. || No applets, please. || Minecraft, Android, and Javascript all have their own channel. || You are being logged.
  67. * nevet joined #java
  68. * zorone joined #java
  69. * zorone joined #java
  70. * zorone joined #java
  71. * pr070cal joined #java
  72. * raj joined #java
  73. * kcomhnall joined #java
  74. * kcomhnall joined #java
  75. * kcomhnal1 joined #java
  76. * stfstfm joined #java
  77. * stfstfm_ joined #java
  78. * ForeverDreaming joined #java
  79. * ptomli8 joined #java
  80. * stfstfm joined #java
  81. * GreenResponse joined #java
  82. * stfstfm joined #java
  83. * stfstfm_ joined #java
  84. * stfstfm joined #java
  85. * stfstfm joined #java
  86. * victori joined #java
  87. * stewi joined #java
  88. * magla joined #java
  89. * MonsterAbyss joined #java
  90. * BarnabasDK joined #java
  91. * mindCrime joined #java
  92. * NeXeN joined #java
  93. * agnivn joined #java
  94. * jiffy__ joined #java
  95. * ForeverDreaming joined #java
  96. * zorone joined #java
  97. * kcomhnall joined #java
  98. * kcomhnal1 joined #java
  99. * MonsterAbyss joined #java
  100. * nevet joined #java
  101. * CodeGeek!~codegeek@about/java/CodeGeek changed the topic to: Welcome! || Read Channel Rules at https://javachannel.org/ before participating. || Paste limit is two lines; ~pastebin lists options. || No applets, please. || Minecraft, Android, and Javascript all have their own channel. || You are being logged.
  102. dmlloyd another thing that is rarely mentioned is that people almost never write Java classes that are just getters and setters of simple data fields in practice; that's like something you only do commonly in introductory examples most of the time
  103. Para Walk before you run.
  104. * ferdna joined #java
  105. * kathadris joined #java
  106. * Fiji joined #java
  107. * stfstfm_ joined #java
  108. * sponkz joined #java
  109. * ferdna joined #java
  110. kcomhnal1 dmlloyd: pretty much. I just use @Data
  111. kcomhnal1 eewww... I'm a clone.
  112. * kcomhnal1 left #java
  113. kcomhnall now its okay
  114. * Ragnor joined #java
  115. dmlloyd I think a far better example is a class with final fields and just getters tbh
  116. dmlloyd records cover that case about 80% of the time
  117. * jink joined #java
  118. kcomhnall what do you guys use to model your schema / hierarchy ? Figma?
  119. * LtHummus joined #java
  120. * skum joined #java
  121. * NeXeN joined #java
  122. * magla joined #java