Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Stoop sed-smells






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Stoop sed-smells Stoop sed-smells Presentation Transcript

  • Elements of Design - Simple Smells Simple Smells
  • Basic Design Mistakes
  • A Class should have
    • Class Person {
      • String getName();
      • void setName(String name);
      • int getAge();
      • void setAge(int age);
      • Car getCar();
      • void setCar(Car car);
    • }
    • What do we see ?
      • A class should have one main responsibility and some behavior not just holding state
      • Minimal access to its data!
  • Confusing
    • Class City extends Place { … }
    • Class Jerusalem extends City implements Capital { … }
    • Class TelAviv extends City { … }
    • What is wrong here?
    • Confusing inheritance and instantiation
    • Too much inheritance?
  • Do not expose implementation
  • Do not overuse conversions
    • nodes asSet
    • removes all the duplicated nodes (if node knows how to compare). But a systematic use of asSet to protect yourself from duplicate is not good
    • nodes asSet asOrderedCollection
    • returns an ordered collection after removing duplicates
    • Look for the real source of duplication if you do not want it!
  • Hiding missing information
    • Dictionary>>at: aKey
    • This raises an error if the key is not found
    • Dictionary>>at: aKey ifAbsent: aBlock
    • Allows one to specify action aBlock to be done when the key does not exist.
    • Do not overuse it:
    • nodes at: nodeId ifAbsent:[ ]
    • This is bad because at least we should know that the nodeId was missing
  • Avoid returning nil
    • Avoid to return special results as nil
    • messages := self fetchMessages.
    • messages isNil
    •   ifFalse: [ messages dispatchFrom: self ]
    • What if we would simply return an empty collection in
    • fetchMessages instead of nil?
    • Less conditional and ugly tests!!
  • Objects not strings!
    • Strings are dead objects
    • You can only concatenate strings
    • Use objects not their textual representation
  • Objects not tuples!
    • spec first
    • spec second
    • spec third
    • spec action
    • spec selector
    • spec menuItem
    • And add a printing
    • aSpec(‘open’, #openBrowser, ‘open (O)’)
  • Tell, Don’t Ask
    • no condition and case based on the receiver type
    • Use polymorphism as much as possible to avoid type checking
  • Tell, Don’t Ask!
    • MyWindow>>displayObject: aGrObject
      • aGrObject displayOn: self
    • And not:
    • MyWindow>>displayObject: aGrObject
      • aGrObject isSquare ifTrue: […]
      • aGrObject isCircle ifTrue: […]
  • Don’t violate encapsulation
    • No overuse of accessors
    • Encapsulation principle: minimize data representation dependencies
    • Offer complete interface