key elements present to formally distinguish an actual AntiPattern from a simple bad habit, bad practice, or bad idea: • A repeated pattern of action, process, or structure that initially appears to be beneficial but ultimately produces more bad consequences than beneficial results • A refactored solution that is clearly documented, proven in actual practice, and repeatable • AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis (William Brown, Raphael Malveau, Skip McCormick, and Tom Mowbray) Saturday, June 15, 13
Stay the Same • Program to an Interface, Not an Implementation • Prefer Composition over Inheritance • Delegate, Delegate, Delegate • YAGNI • and many more - specific to ruby Saturday, June 15, 13
Duplicate Code Duplication • Authorization Astronaut • The Million Model March • PHPitis • Markup Mayhem • Homemade Keys • Fat Controller • Bloated Sessions • Monolithic Controllers • Controller of Many Faces • A Lost Child Controller • Rat’s Nest Resources • and many more Saturday, June 15, 13
@invoice.customer.address.city %> <%= @invoice.customer.address.state %> <%= @invoice.customer.address.zip_code %> class Address < ActiveRecord::Base belongs_to :customer end class Customer < ActiveRecord::Base has_one :address has_many :invoices end class Invoice < ActiveRecord::Base belongs_to :customer end Saturday, June 15, 13
OOP concepts. • The other three are inheritance, polymorphism, and abstraction. • makes class members (variables and methods) private, and only allows access thorough public methods. • a wall protecting your data from being modified, or accessed in ways that you, the programmer, may not want. In properly encapsulated code data inside a class is only accessible through these public interfaces. • Benefit: ability to modify our code without breaking other parts of our program, makes our programs much easier to maintain, extend, and gives you much more flexibility. Saturday, June 15, 13