Yii Framework Forum: Public properties on classes - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Public properties on classes

#1 User is offline   TinweDeveloper 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 30-November 17

Posted 15 May 2018 - 03:12 PM

Do you think guys that configurable classes should use public properties? Why it's bad? For me it's not safe casting we can push to set (string) (int) whatever of course we configure this class but sometimes you can forget which type it's use.Additionaly it's bad OOP design. What do you think?
0

#2 User is offline   itma 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 134
  • Joined: 16-September 13

Posted 15 May 2018 - 03:57 PM

If you care of the proper types pushed into the class variables then using public isnt't a good choice. In general you should use setters for that and operate on private/proteced properties. It will allow you to check, filter, etc. the data coming as the value.

Hope it helps :)
A full stack developer for hire (andrew@itma.pl)
https://twitter.com/Andrew_Bernat
0

#3 User is offline   TinweDeveloper 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 30-November 17

Posted 15 May 2018 - 05:08 PM

Yes, i know but if we will go to the core yii2 there is a a lotof public without setter / getters. It's making me frustrate beacuse it damage to encapsulation OOP paradigm
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,648
  • Joined: 16-February 11
  • Location:Japan

Posted 16 May 2018 - 09:03 AM

Hi TinweDeveloper,

You know, the Guide says the following in "What is Yii"(https://www.yiiframe....0/en/intro-yii):

Quote

Yii takes the philosophy that code should be written in a simple yet elegant way. Yii will never try to over-design things mainly for the purpose of strictly following some design pattern.


Writing setter and getter for each and every public properties won't help you much in real world development, I think.
0

#5 User is offline   TinweDeveloper 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 30-November 17

Posted 17 May 2018 - 04:39 AM

On configuration yes it's true but with transfer data it's huge problem.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users