Of the SOLID principles, made famous by Robert C. Martin, we'll discuss the Single Responsibility Principle and the Open/Closed Principle, two of the presenter's favorite principles. But at the same time the least understood and used principles. That's why this session will explain them thoroughly and give real life examples instead of the regular customer & order examples. You'll walk away knowing what the benefits are and how to use them properly.
1. SOLID
Single Responsibility Principle
Open/Closed Principle
Dennis van der Stelt Pascal de Jonge
Software Architect Development Lead
Tellus Tellus
http://bloggingabout.net/blogs/dennis/ http://www.pazquality.com/
@dvdstelt @pdejonge
dvdstelt@tellus.com pdejonge@tellus.com
Software Development Network 2013
6. SOLID
Five principles
Single Responsibility SOLID Open/Closed
Liskov Substitution Interface Seggregation Dependency Inversion
Learn them, love them, live by them…
Software Development Network 2013
12. SINGLE RESPONSIBILITY PRINCIPLE
Rules that apply to classes
rule rule same goes for methods,
they should be small which we count by #
01 03 lines
rule rule
they should be smaller how to measure class
02 than that 04 size?
Responsibility : “a reason for change”
Software Development Network 2013
15. SINGLE RESPONSIBILITY PRINCIPLE
Sometimes hard to see…
interface IModem
{
void Dial(string phoneNumber);
void Hangup();
void Send(char c);
char Receive();
}
Software Development Network 2013
16. SINGLE RESPONSIBILITY PRINCIPLE
public interface IConnection
{
void Dial(string phoneNumber);
void Hangup();
}
public interface IDataChannel
{
void Send(char c);
char Receive();
}
public class Modem
{
public Modem(IConnection connection, IDataChannel dataChannel)
{
// ...
}
}
Software Development Network 2013
17. SINGLE RESPONSIBILITY PRINCIPLE
Rule of thumb
If you can’t come up with a
name for your class, it’s probably doing too much!
Software Development Network 2013
19. SINGLE RESPONSIBILITY PRINCIPLE
Violation
• God class unneeded complexity
Don’t create
• However
public class OrderService
{
public Order Get(int orderId) { }
public Order Get(string name) { }
public Order Save(Order order) { }
public Order SubmitOrder(Order order) { }
public void CancelOrder(Order order) { }
public void ProcessOrderReturn(int orderId) { }
public void ShipOrder(Order order) { }
}
Software Development Network 2013
20. more classes != more
complex
Software Development Network 2013
26. TEMPLATE METHOD PATTERN
AbstractBase class
Program Initialize
SendMessage
Finalize
Execute
EmailSende
r
SendMessage
Software Development Network 2013
28. CONCLUSION
Single Responsibility SOLID Open/Closed
Liskov Substitution Interface Seggregation Dependency Inversion
Software Development Network 2013
29. Thank you
questions?
Dennis van der Stelt Pascal de Jonge
Software Architect Development Lead
Tellus Tellus
http://bloggingabout.net/blogs/dennis/ http://www.pazquality.com/
@dvdstelt @pdejonge
dvdstelt@tellus.com pdejonge@tellus.com
33
Software Development Network 2013
Editor's Notes
There are other talks that will go into Big Data and Hadoop so we’ll only do a quick overview of that right now. We’ll spend most of our time on Hive.
5 basic principles of OOPDIntroduced in 2000By Robert C. Martin (Uncle Bob)Whenapplied, more likelyto have a bettermaintainableandextendable system over time.
Guidelines, not hard rules, not a dogmaUse common senseDon’tjustthrowthemaway
Major problem, as we have toinclude GUI related .dll’stoourGeometryService, but it NEVER uses these.
Major problem, as we have toinclude GUI related .dll’stoourGeometryService, but it NEVER uses these.
What is wrong with this modem interface?Answer :Connection & Data Transfer are combined
What is wrong with this modem interface?Answer :Connection & Data Transfer are combined
Don’tcreatedunneededcomplexityHowever, more classes != more complexityThis is supposedto make your life easier!But noteasiertobelazy
Classes are organized, as top left pictureNot chaos, like bottom right picture
What do you like more?Changing other people’s code?Or writing new code?
OCPExisting code should not be edited when new functionality is added, because…don’tneedto re-test working code;don’tneed new code reviews;don’tneedtoexamindependent code
Some examples of organizations that delivering new value based in the form of revenue growth, cost savings or creating entirely new business models.Yahoo - AS with Hive, Klout - AS with Hive (white paper), GE - Hive AnalyticsYahoo! (Gartner BI Excellence Award Winner) is driving growth for existing revenue streams:Yahoo! manages a powerful, scalable advertising exchange that includes publishers and advertisers.Advertisers want to get the most out of their investment by reaching their targeted audiences effectively and efficiently.Yahoo! needs visibility into how consumers are responding to ads alongmany dimensions (websites, creative, time of day, gender, age, location) to make the exchangework as efficiently and effectivelyas possible.Yahoo! doubled its revenue by allowing campaign managers to “tune” campaign targeting and creative.Yahoo! drove an increase in spending from advertisers since they got better performance by advertising through Yahoo!.Yahoo! TAO exposed customer segment performance to campaign managers and advertisers for the first time.Klout is creating new businesses and revenue streams:Klout’s mission is to help everyone understand and leverage their influence. Klout uses Big Data to unify the social web (consumers, brands, and partners) with social networking and activity, along with data to generate a Klout score and enable analysis, targeting, and social graphs.Helps consumers manage their “social brand.”Helps brands reach influencers at scale.Helps data partners enhance their services (customer loyalty, CRM, media and identity, and marketing). For example, the Palms uses Klout scores in addition to their normal customer rewards program to determine whether or not to upgrade their customers to a better room during their stay. The Huffington Post uses Klout to help serve the best curated Twitter content.Klout Case Study: http://www.microsoft.com/casestudies/Microsoft-SQL-Server-2012-Enterprise/Klout/Data-Services-Firm-Uses-Microsoft-BI-and-Hadoop-to-Boost-Insight-into-Big-Data/710000000129Case Study on Thailand’s Department of Special Investigations : http://www.microsoft.com/casestudies/Microsoft-SQL-Server-2012-Enterprise/Department-of-Special-Investigation/Thai-Law-Enforcement-Agency-Optimizes-Investigations-with-Big-Data-Solution/710000001175 GE is driving operational efficiencies:GE is running several use cases on its Hadoop cluster while incorporating several different disparate sources to produce results. Along with sentiment analysis, GE is running web analytics on its internal cloud structure and looking at load usage, user analytics, and failure mode analytics. GE built a recommendation engine for its intranet involving various press releases users might be interested in based on their function, user profiles, and prior visits to its site. GE is working with several types of remote monitoring and diagnostic data from energy and wind businesses.
Big data is often described as problems that have one or more of the 3 (or 4) Vs – volume, velocity, variety, variability. Think about big data when you describe a problem with terms like tame the chaos, reduce the complexity, explore, I don’t know what I don’t know, unknown unknowns, unstructured, changing quickly, too much for what my environment can handle now, unused data.Volume = more data than the current environment can handle with vertical scaling, need to make sure of data that it is currently too expensive to useVelocity = Small decision window compared to data change rate, ask how quickly you need to analyze and how quickly data arrivesVariety = many different formats that are expensive to integrate, probably from many data sources/feedsVariability = many possible interpretations of the data