Testing Blog

How to think about OO

Friday, July 31, 2009
Share on Google+ Share on Twitter Share on Facebook
Google
Labels: Misko Hevery

5 comments :

  1. Camilo A.July 31, 2009 at 3:58 PM

    I mostly agree with your idea about static methods. But what about operations that depend of both arguments equally? For example Math.min or Math.max. Should we really have a 5.min(3)? It sounds counter intuitive to me. I think it is better to have a static method called min(3,5). In an ideal language, this would be a global function. Notice that since it has no global state, no testability is lost.

    ReplyDelete
    Replies
      Reply
  2. liquidAugust 3, 2009 at 4:42 AM

    Wouldn't the last change make it more difficult to promote a User to SuperUser?, I mean, wouldn't the viability of this change be dependant on stuff like this?

    ReplyDelete
    Replies
      Reply
  3. Gary PamparaAugust 5, 2009 at 12:52 AM

    I cannot agree more. Static state is terrible! People often say that it is not the case, but once it bites you in the behind, you will never think the same again.

    I have a question, what would be a possible solution to a global class that returns some state when a get() (yes, static) is called on it? I would love to refactor the code in such away that get() is no longer needed. Any advice would be greatly appreciated... this has been annoying me for a long long time.

    ReplyDelete
    Replies
      Reply
  4. Richard MinerichAugust 5, 2009 at 6:33 AM

    I disagree with you in that I think static methods are just fine as long as they do not maintain global state. This is mainly due to the DRY principle.

    Given a function of two differently typed arguments, let's call them X and Y, it would be bad design to implement X(Y) and Y(X) in different places in your code as whenever X(Y) had to be updated, so would Y(X). This may seem like a corner case but many variations on this theme frequently occur in large projects.

    ReplyDelete
    Replies
      Reply
  5. TetsuoAugust 27, 2009 at 1:59 PM

    That User/SuperUser/AgentUser thing is beautiful in theory, but hard to achieve in practice.

    What if you can change the type of a user, from 'agent' to 'super'? Most languages won't let you do it. ORM frameworks (Hibernate) won't let you do it. At least not in a nice, clean way. Also, what about the 'composition over inheritance' principle?

    About the static methods rant, how to avoid an explosion in the number of methods in basic classes, like string and number? String.toJDOMElementTree() would be a candidate?

    I don't disagree with you, in that people could do much, much better.

    It's just funny. People discuss design principles as if they were a cohesive, coherent, single body of absolute truth, when in reality most of them are disconnected, contradictory, context-specific rules, that are all correct individually, but nearly impossible to be fully followed together.

    For example, how to maximize encapsulation of a class, without violating the 'S' in SOLID? Or, how to maximize reuse (DRY) without raising coupling, while keeping it simple?

    What I'm trying to say is, to design is to make choices and to balance trade-offs. And accepting the limitations of your environment. As Eric Evans said in his book, don't fight your tools, don't fight your frameworks.

    But, you should always try to do your best! :)

    ReplyDelete
    Replies
      Reply
Add comment
Load more...

  

Labels


  • Aaron Jacobs 1
  • Adam Porter 1
  • Alan Faulkner 1
  • Alan Myrvold 1
  • Alberto Savoia 4
  • Alek Icev 2
  • Alex Eagle 1
  • Allen Hutchison 6
  • Andrew Trenk 8
  • Android 1
  • Anthony Vallone 25
  • Antoine Picard 1
  • APIs 2
  • App Engine 1
  • April Fools 2
  • Arif Sukoco 1
  • Bruce Leban 1
  • C++ 11
  • Chaitali Narla 2
  • Christopher Semturs 1
  • Chrome 3
  • Chrome OS 2
  • Dave Chen 1
  • Diego Salas 2
  • Dmitry Vyukov 1
  • Dori Reuveni 1
  • Eduardo Bravo Ortiz 1
  • Ekaterina Kamenskaya 1
  • Erik Kuefler 3
  • Espresso 1
  • George Pirocanac 2
  • Google+ 1
  • Goranka Bjedov 1
  • GTAC 54
  • Hank Duan 1
  • Harry Robinson 5
  • Havard Rast Blok 1
  • Hongfei Ding 1
  • James Whittaker 42
  • Jason Arbon 2
  • Jason Elbaum 1
  • Jason Huggins 1
  • Java 5
  • JavaScript 7
  • Jay Han 1
  • Jessica Tomechak 1
  • Jim Reardon 1
  • Jobs 14
  • Joe Allan Muharsky 1
  • Joel Hynoski 1
  • John Penix 1
  • John Thomas 3
  • Jonathan Rockway 1
  • Jonathan Velasquez 1
  • Julian Harty 5
  • Julie Ralph 1
  • Karin Lundberg 1
  • Kaue Silveira 1
  • Kevin Graney 1
  • Kirkland 1
  • Kurt Alfred Kluever 1
  • Lesley Katzen 1
  • Marc Kaplan 3
  • Mark Ivey 1
  • Mark Striebeck 1
  • Marko Ivanković 1
  • Markus Clermont 3
  • Michael Bachman 1
  • Michael Klepikov 1
  • Mike Wacker 1
  • Misko Hevery 32
  • Mobile 2
  • Mona El Mahdy 1
  • Noel Yap 1
  • Patricia Legaspi 1
  • Patrick Copeland 23
  • Patrik Höglund 5
  • Peter Arrenbrecht 1
  • Phil Rollet 1
  • Philip Zembrod 4
  • Pooja Gupta 1
  • Radoslav Vasilev 1
  • Rajat Dewan 1
  • Rajat Jain 1
  • Rich Martin 1
  • Richard Bustamante 1
  • Roshan Sembacuttiaratchy 1
  • Ruslan Khamitov 1
  • Sean Jordan 1
  • Sharon Zhou 1
  • Shyam Seshadri 4
  • Simon Stewart 2
  • Stephen Ng 1
  • Tejas Shah 1
  • Test Analytics 1
  • Tony Voellm 2
  • TotT 54
  • Vojta Jína 1
  • WebRTC 2
  • Yvette Nameth 2
  • Zhanyong Wan 6
  • Zuri Kemp 2


Archive


  •     2015
    •     December
    •     November
    •     October
    •     August
    •     June
    •     May
    •     April
    •     March
    •     February
    •     January
  •     2014
    •     December
    •     November
    •     October
    •     September
    •     August
    •     July
    •     June
    •     May
    •     April
    •     March
    •     February
    •     January
  •     2013
    •     December
    •     November
    •     October
    •     August
    •     July
    •     June
    •     May
    •     April
    •     March
    •     January
  •     2012
    •     December
    •     November
    •     October
    •     September
    •     August
  •     2011
    •     November
    •     October
    •     September
    •     August
    •     July
    •     June
    •     May
    •     April
    •     March
    •     February
    •     January
  •     2010
    •     December
    •     November
    •     October
    •     September
    •     August
    •     July
    •     June
    •     May
    •     April
    •     March
    •     February
    •     January
  •     2009
    •     December
    •     November
    •     October
    •     September
    •     August
    •     July
      • How to think about OO
      • Call for Attendance: Google Test Automation Confer...
      • The Plague of Blindness
      • Update! GTAC Keynote Speakers: Niklaus Wirth and A...
      • The Plague of Homelessness
      • Blog Stats
      • The Plague of Boredom
      • Blog Editor: Moderating Comments
      • The Advantages of Unit Testing Early
      • Software Testing Categorization
      • The Plague of Amnesia
      • Update! Google Test Automation Conference: Website...
      • Old habits die hard
      • Why are we embarrassed to admit that we don't know...
      • Separation anxiety?
    •     June
    •     May
    •     April
    •     February
    •     January
  •     2008
    •     December
    •     November
    •     October
    •     September
    •     August
    •     July
    •     June
    •     May
    •     April
    •     March
    •     February
    •     January
  •     2007
    •     October
    •     September
    •     August
    •     July
    •     June
    •     May
    •     April
    •     March
    •     February
    •     January

Feed

Company-wide

  • Official Google Blog
  • Public Policy Blog
  • Student Blog

Products

  • Google for Work Blog
  • Chrome Blog
  • Official Android Blog

Developers

  • Ads Developer Blog
  • Android Developers Blog
  • Developers Blog
  • Google
  • Privacy
  • Terms