Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 32
  1. #11

    Default Re: OOP: are getters/setters evil

    @yanong_banikanhon ok, i may have not clarified my point well.. sorry for my crappy words.. galisud gyud kog pasabot... sakto ka wala ko mag expose og implementation.. ang ako tag e point out is you are letting external entities to use your setters and getters what would happen if ma change ang implementation sa imong setters og getters is daghan ma apektohan for example if ang implementation sa setters/getters
    Code:
    int getBalance();
    void setBalance(int);
    
    //into
    double getBalance();
    void getBalance(double);
    
    
    Class UserClass1
    {
       private PrintCustomerBalance()
       {
         Customer cust = new Customer("CUST01");
         int bal = cust.getBalance(); // needs to change
         print(bal.toString());
       }
    }
    this would require all classes nga naggamit ana nga mga setters and getters to be changed pud..

    anyways, mao na syay gi imposed ta sa gang of four.. if you read their books mao na ilang pasabot nganong evil na sya, pero that doesnt mean nga dli ka angay mo gamit ana depende na sa imong design. try to read sa link nga gi post sa TS mao sad ang gi sulti didto.

    also try dont myn nlng ng ingn ana nga issue since most IDE karon naay refractoring nga feature. saun man tanang gang of 4 karaan mana sila.. lol..

    also, setters/getters are only evil in strongly type languages, java, C#.net.. if adto ni sa mga scripting languages like python wala mani problema since dili man ka mag declare, tanan variant man.

    thats why nag design sa java mo ana gyud nga python ang best language with regards to pattern

  2. #12

    Default Re: OOP: are getters/setters evil

    Quote Originally Posted by fixyourself View Post
    Code:
    int getBalance();
    
    //into
    double getBalance();
    void getBalance(double);
    
    
    Class UserClass1
    {
       private PrintCustomerBalance()
       {
         Customer cust = new Customer("CUST01");
         int bal = cust.getBalance(); // needs to change
         print(bal.toString());
       }
    }
    this would require all classes nga naggamit ana nga mga setters and getters to be changed pud..
    Curious lang ko bay. Without using a getter, can you provide a way nga dili maapektahan ang UserClass1 kung ang type sa balance changed from int to double?

    Mora'g dili man siguro ni unique sa getter/setter. This also applies to public methods as well. Kung mausab gani ang signature sa public method, kinahanglan gyud pud i-update ang mga codes nga nigamit aning maong method.

    Sama sa gisulti sa article nga na-mention sa taas, mahimo lang sayop ang paggamit sa setter/getter kun ang ilang purpose sa usa ka class is nothing more than pointless proxies for direct access to the object’s private data. Mao nay makaguba sa encapsulation.

  3. #13

    Default Re: OOP: are getters/setters evil

    Quote Originally Posted by yanong_banikanhon View Post
    Curious lang ko bay. Without using a getter, can you provide a way nga dili maapektahan ang UserClass1 kung ang type sa balance changed from int to double?

    Mora'g dili man siguro ni unique sa getter/setter. This also applies to public methods as well. Kung mausab gani ang signature sa public method, kinahanglan gyud pud i-update ang mga codes nga nigamit aning maong method.

    Sama sa gisulti sa article nga na-mention sa taas, mahimo lang sayop ang paggamit sa setter/getter kun ang ilang purpose sa usa ka class is nothing more than pointless proxies for direct access to the object’s private data. Mao nay makaguba sa encapsulation.
    yup.. mao rana.. it was just an example. there is no harm in using setters and getters, sa amoa nga side daghan gani kaaung setters/getters. actually i am not so into the gang of 4's idea that settters and getters are evil.

    If the gang of 4 maoy mo iplement ana atong example sa babaw, murag anion na nila, but im not sure

    Code:
    Money getBalance();
    void setBalance(MOney);
    they will let the money class handle all logics regarding currencies, including exchange rate, currency, and blah2x..

  4. #14

    Default Re: OOP: are getters/setters evil

    Morag mao ra gihapong problemaha, bay. Kanang Money nga class, kinahanglan pud na og 'getAmount' nga getter or public method. Kun ang return type sa 'getAmount' mausob (from int to double), wala gihapon tay lusot. kinahanglan gihapon usbon ang mga codes nga dunay 'money.GetAmount();'.

    Ingon gyud ana siguro ang software development, halos tanan trade-off. There is no silver-bullet, no fool-proof approach. It all depends on a given situation. Anha nato makita ang kamaayo sa usa ka developer kun mohimo siya og mga decision that seem to defy conventional wisdom and comes up with the optimum result.

  5. #15

    Default Re: OOP: are getters/setters evil

    Quote Originally Posted by yanong_banikanhon View Post
    Morag mao ra gihapong problemaha, bay. Kanang Money nga class, kinahanglan pud na og 'getAmount' nga getter or public method. Kun ang return type sa 'getAmount' mausob (from int to double), wala gihapon tay lusot. kinahanglan gihapon usbon ang mga codes nga dunay 'money.GetAmount();'.

    Ingon gyud ana siguro ang software development, halos tanan trade-off. There is no silver-bullet, no fool-proof approach. It all depends on a given situation. Anha nato makita ang kamaayo sa usa ka developer kun mohimo siya og mga decision that seem to defy conventional wisdom and comes up with the optimum result.
    not really, dili sila mo expose og mga methods nga ingn ana...

    murag if mo increase sila moa ni ra sila

    Money.IncreaseBy(Money);
    Money.DecreaseBy(Money);

    instead of
    Money a, b;
    double t = a.getAmount() - b.getAmount();

    so all logic regarding operation is adto sulod sa money class. mag expose silag get sguro pero dili mag set.

    plus, dili sila nagagamit anang getAmount gyud nga method sa ubang classes para dili ma apektohan ang uban, again the Money class will handle all operations. so if naay changes sa data types baron Money class rai apektohan, but sakto ka walai perfect nga approach.

    edit* add code para maklaro

    Code:
    class Money
    {
      
      private double m_amount = 0;
      public double getAmount()
      {
        retuern m_amount;
      }
    
      public void IncreaseBy(Money money)
      {
        m_amount += money.getAmount();
      }
    }
    but im sure naa gyapon nay sayup labi na sa constructor.

  6. #16

    Default Re: OOP: are getters/setters evil

    Quote Originally Posted by fixyourself View Post
    dili sila nagagamit anang getAmount gyud nga method sa ubang classes para dili ma apektohan ang uban, again the Money class will handle all operations. so if naay changes sa data types baron Money class rai apektohan
    Suppose I want to know the average balance of five customers. How can I do that if there is no getter or public method in the Money class that returns its actual amount?

  7. #17

    Default Re: OOP: are getters/setters evil

    Quote Originally Posted by yanong_banikanhon View Post
    Suppose I want to know the average balance of five customers. How can I do that if there is no getter or public method in the Money class that returns its actual amount?
    sorry, there is a public getter, but limit its use in other classes. It is needed even inside the Money.IncreaseBy implementation.

    Money //class
    {

    public static Money getAverage(params Money)
    {
    //loop throughout all the moeny parameters and get the average
    //instantiate a new money, as I said the problem with this one is the constructor
    //return the newly instantiated money
    }
    }

  8. #18

    Default Re: OOP: are getters/setters evil

    And if there is a requirement to plot the balance average and the customers' individual balances in, say for example, a bar graph. Are you going to use the 'getAmount' getter here?

    *** Note that the BarGraph class is an outside class, probably written by somebody else.

  9. #19

    Default Re: OOP: are getters/setters evil

    tell me unsa nga klase nga graph, ill try to provide a solution if i can, without using getAmount from outside? e describe ang graph nga buhaton..

    anyway, i dont know ngano ni defend ko aning idea sa gang of 4 nga evil ning setters/getters nga tiggamit man ko ani.. lol..

    also kudos to you @yanong_banikanhon, gamay rakaau ta tig post dire kanang mga naay sense, uban sige lang nag pahimo project.. haha..

    back to the topic, try to describe the graph daw bai nya akong suwayan og pangitag paagi..

  10. #20

    Default Re: OOP: are getters/setters evil

    Quote Originally Posted by yanong_banikanhon View Post

    *** Note that the BarGraph class is an outside class, probably written by somebody else.
    if this is the case an external class will be responsible for creating the graph then i guess there is no choice. as we both agreed setters/getters are not that evil. lol.

    but a possible solution though is to let money class implement an interface to be used by the grapher class in plotting the graph.

Page 2 of 4 FirstFirst 1234 LastLast

Similar Threads

 
  1. how EVIL are you?
    By potterboy in forum General Discussions
    Replies: 149
    Last Post: 03-24-2015, 01:43 PM
  2. Proof that GIRLS are EVIL
    By xaired in forum General Discussions
    Replies: 177
    Last Post: 12-08-2013, 11:50 AM
  3. Women Are Evil By Nature!!
    By SQUiDnine in forum Humor
    Replies: 44
    Last Post: 04-30-2011, 09:24 AM
  4. Which are you, Go Getter? or Seek Explorer?
    By franz_fry in forum General Discussions
    Replies: 20
    Last Post: 07-02-2009, 01:50 PM
  5. Proof that girls are evil!!
    By awan in forum Humor
    Replies: 57
    Last Post: 02-01-2007, 10:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top