In SharePoint -
Download
Report
Transcript In SharePoint -
Object Oriented Development and Practices
In SharePoint
Mostly
Introduction
» Charles Chen (Me)
» Blog thingy: http://www.charliedigital.com
» .NET, SharePoint, Office, Web
» Slide deck and related posts (with code!)
» Background
» .NET since version 1 (Java and ASP before that)
» SharePoint development since 2007 beta 2
» Then: product development on SharePoint/Office platform
» Now: solution development on SharePoint/Office platform
» Paragon Solutions (My Employer)
» http://consultparagon.com
Key Takeaways (In a Few Bullet Points)
» “No Silver Bullet” – Fred Brooks
» Ideas for Building SharePoint Solutions for:
» Approachability – Easy for new developers to ramp up
» Agility – Easy to extend and build new features
» Consistency – Highly conformant code and patterns (DRY)
» Maintainability – Easy to maintain and fix
» Tips for Leveraging the Platform (.NET and SharePoint)
» Lots of code! Concrete examples.
» Start Thinking About Frameworks and Teams
» Developers take the path of least resistance (make it easy
to write good code).
» Make your entire team productive
So What Is Object Oriented Code?
» Text-book Definition:
» Objects and classes – a tight coupling or association of
data structures with the methods or functions that act on
the data
» Encapsulation – protect components of a class from
external entities (hide complexity)
» Inheritance – ability for a class to extend or override
functionality in another class
» Interfaces – ability to defer implementation with a
contract
» Polymorphism – ability to replace an object with a subobject
» Winner? – Next what is an “anemic domain model”?
Anemic Domain Models
» What is It?
» An “anti-pattern” (Martin Fowler)
» Logic cannot be implemented in a truly object-oriented
way unless wrappers are used, which hide the anemic data
structure.
» Facilitates code duplication among transactional scripts
and similar use cases, reduces code reuse.
» Necessitates a service layer when sharing domain logic
across differing consumers of an object model.
» Makes a model less expressive and harder to understand.
(Less visibility.)
» So You Have an Anemic Domain Model, Now What? (link)
Approachability
“A habit cannot be tossed out the window; it must
be coaxed down the stairs a step at a time.”
– Mark Twain
Approachability
» Old Habits Die Hard
» SharePoint development is foreign to ASP.NET developers
» …But ASP.NET developers are easy to come by
» Watch out for bad SharePoint development practices
» Approach: Make it easy for them to stay in their domain
» Minimize Challenges
» Structure solution to isolate SharePoint from ASP.NET code
» Take the challenge out of packaging and deployment
» Obfuscation of complex moving parts (more later…)
» Code Walkthrough
Agility
“The speed of a runaway horse counts for nothing.”
– Jean Cocteau
Agility
» What Is It?
» Ability to implement new functionality, quickly
» Ability to make changes to existing functionality, quickly
» Ability to adjust rapidly to changing requirements, quickly
» How is Agility Attained?
» Reduce duplication in code
» Reduce duplicate effort
» Reduce manual steps
» Object-oriented semantics – Domain Model (more later…)
» Just Being Quick is not Good Enough
» Code needs to stay “clean” to promote future agility
Consistency
“Intuition will tell the thinking mind where to look next.”
– Jonas Salk
Consistency
» Conceptual Integrity
» “Conceptual integrity is the most important consideration
in system design.” – Fred Brooks
» How to build on the framework and use existing artifacts
should be intuitive
» Increase approachability by emphasizing consistency in
programming model
» How to Achieve?
» We saw some of it already – automation
» Avoid Anemic Domain Models
» Leverage patterns when applicable
» Abstract common behaviors (DRY)
Patterns – Table Data Gateway
» What is It? Fowler:
» “Mixing SQL in application logic can cause several
problems. Many developers aren't comfortable with SQL,
and many who are comfortable may not write it well.
Database administrators need to be able to find SQL easily
so they can figure out how to tune and evolve the
database.”
» “A Table Data Gateway holds all the SQL for accessing a
single table or view: selects, inserts, updates, and deletes.
Other code calls its methods for all interaction with the
database.”
» Code Samples – “List Data Gateways”
Maintainability
“Another flaw in the human character is that everybody
wants to build and nobody wants to do maintenance.”
– Kurt Vonnegut Jr.
Maintainability
» The Ugly Truth:
» SharePoint code is fraught with string references
» CAML strings
» Library, content type, and field names
» Hard to find and fix everything
» Runtime errors as opposed to compile time errors
» Redeploying packages is time consuming
» Hard to trace errors (log4net to the rescue!)
» A Path Forward
» Query framework for 2007 and 2010
» SPMetal (if it suits your tastes) in 2010
» Let’s look at code…
?
Questions? Feedback?
More demos?
Charles Chen | http://charliedigital.com | [email protected]