This document provides an agenda and overview for a presentation on foundations of programming and building better software. The presentation covers topics like ALT.NET principles, domain driven design, persistence, dependency injection, unit testing, object relational mappers and conclusions. It discusses domain objects, data driven vs domain centric design, and bridging the gap between objects and relational databases. Code examples are provided for domain models, data access and mapping objects to database tables.
MoDELS'16 presentation: Integration of a Graph-Based Model Indexer in Commerc...Antonio García-Domínguez
In this MoDELS'16 paper, we show how the Hawk model indexer was extended to index Modelio models, and how it was embedded into the Constellation collaboration server from SOFTEAM to allow for efficient querying and metric extraction from its web-based interface.
EASY SOFTWARE DEVELOPMENT BY AUTOMATIC CODE GENERATION, BUSINESS LOGIC AND VA...ijiert bestjournal
In today�s fast and progressive world is process op timization become essential in all fields of life a nd an IT industry is no exception to this. The Integrated Development Environment (IDE) based software development envir onments are popular for easier and faster project developme nt using Drag and Drop (DND) tool box with all esse ntial controls like text box,labels,buttons,etc. This helps developer to design Graphical User Interface (GUI) or User Interface(UI) just with mouse click. Though the des igning of UI and Code generation as templates is ea sier using these tools but none of the existingtoolsare capabl e of generating complete working code with embeddin g �Business Logic� (BL) automatically in code. The vendor speci fic tools from ORACLE,Microsoft,IBM mainframe and some similar tools from other giant vendors are used to design and develop the products for analysis and re porting purpose but these tools need the proprietary DB and vendor specific environment to develop the project.
MoDELS'16 presentation: Integration of a Graph-Based Model Indexer in Commerc...Antonio García-Domínguez
In this MoDELS'16 paper, we show how the Hawk model indexer was extended to index Modelio models, and how it was embedded into the Constellation collaboration server from SOFTEAM to allow for efficient querying and metric extraction from its web-based interface.
EASY SOFTWARE DEVELOPMENT BY AUTOMATIC CODE GENERATION, BUSINESS LOGIC AND VA...ijiert bestjournal
In today�s fast and progressive world is process op timization become essential in all fields of life a nd an IT industry is no exception to this. The Integrated Development Environment (IDE) based software development envir onments are popular for easier and faster project developme nt using Drag and Drop (DND) tool box with all esse ntial controls like text box,labels,buttons,etc. This helps developer to design Graphical User Interface (GUI) or User Interface(UI) just with mouse click. Though the des igning of UI and Code generation as templates is ea sier using these tools but none of the existingtoolsare capabl e of generating complete working code with embeddin g �Business Logic� (BL) automatically in code. The vendor speci fic tools from ORACLE,Microsoft,IBM mainframe and some similar tools from other giant vendors are used to design and develop the products for analysis and re porting purpose but these tools need the proprietary DB and vendor specific environment to develop the project.
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...Sparkhound Inc.
Whether developing a small customization or a large enterprise solution, one goal is to minimize redundancy in Code. In this presentation, Sparkhound Consultant Ted Wagner shows how the MVP design pattern is used in SharePoint to create business models that can be reused easily between other ASP or C# application.
Neoito — Design patterns and depenedency injectionNeoito
Dependency injection is a software design pattern that allows someone to remove hard-coded dependencies and makes it possible to change them. Dependencies can be injected to the object via the constructor or via defined method or a setter property.
Faiz Mohamed Haneef is currently the CEO and Chief Technology Architect at Neoito. He's a former Architect at Lowe's, Hallmark and Infosys.
This is a Introduction to Object Oriented (OO) Concepts, Java Programming Language and leveraging Eclipse (IBM WebSphere) to develop Java applications.
This is based on JDK 1.4 concepts/features. A newer version maybe provided at a future date.
Through this presentation you will gain a good understanding of how the clean architecture pattern is implemented at Taxibeat. What issues the Android Taxibeat team has faced so far and what solutions we came up with. Of course, the benefits of clean architecture will also be discussed along with the way we managed to build two fast paced iterative apps that share functionality.
Developing Next-Gen Enterprise Web ApplicationMark Gu
Mark Gu, web architect from SunGard (Asset Finance), will be giving a presentation on how they are using ASP.NET MVC and various client-side technologies to develop their next generation Enterprise web application. The presentation will cover topics and promote discussions around pluggable websites, Knockout JS, Roslyn, code generation, and TypeScript just to name a few.
Connect 2014 - BP202: Rapid XPages Development Using the Application Layout C...Howard Greenberg
The Application Layout control may be the most useful and powerful tool available to an XPages developer. Learn how to enable and effectively use it to design a consistent user interface using IBM OneUI. Explore and compare several application layout design strategies using the application layout control. Understand how a well designed application layout can be used to provide a consistent design across all of your XPages applications and increase your XPages development productivity. See how the Bootstrap4XPages OpenNTF project can be used to with the application layout control to provide a responsive design for desktop, tablet and mobile devices using Twitter Bootstrap.
Speakers: Howard Greenberg and Paul Della-Nebbia from TLCC
Actively looking for an opportunity to work as a challenging Dot Net DeveloperKarthik Reddy
The .Net Developer designs, modifies, develops, writes and implements software programming applications and components. Supports and/or installs software applications and components. Works from written specifications and pre-established guidelines to perform the functions of the job and maintains documentation of process flow.
Actively looking for an opportunity to work as a challenging Dot Net DeveloperKarthik Reddy
The .Net Developer designs, modifies, develops, writes and implements software programming applications and components. Supports and/or installs software applications and components. Works from written specifications and pre-established guidelines to perform the functions of the job and maintains documentation of process flow.
Any structure expected to stand the test of time and change needs a strong foundation! Software is no exception. Engineering your code to grow in a stable and effective way is critical to your ability to rapidly meet the growing demands of users, new features, technologies, and platform capabilities. Join us to obtain architect-level design patterns for use in your Apex code to keep it well factored, easy to maintain, and in line with platform best practices. You'll follow a Force.com interpretation of Martin Fowler's Enterprise Architecture Application patterns, and the practice of Separation of Concerns.
Graspan: A Big Data System for Big Code AnalysisAftab Hussain
We built a disk-based parallel graph system, Graspan, that uses a novel edge-pair centric computation model to compute dynamic transitive closures on very large program graphs.
We implement context-sensitive pointer/alias and dataflow analyses on Graspan. An evaluation of these analyses on large codebases such as Linux shows that their Graspan implementations scale to millions of lines of code and are much simpler than their original implementations.
These analyses were used to augment the existing checkers; these augmented checkers found 132 new NULL pointer bugs and 1308 unnecessary NULL tests in Linux 4.4.0-rc5, PostgreSQL 8.3.9, and Apache httpd 2.2.18.
- Accepted in ASPLOS ‘17, Xi’an, China.
- Featured in the tutorial, Systemized Program Analyses: A Big Data Perspective on Static Analysis Scalability, ASPLOS ‘17.
- Invited for presentation at SoCal PLS ‘16.
- Invited for poster presentation at PLDI SRC ‘16.
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...Sparkhound Inc.
Whether developing a small customization or a large enterprise solution, one goal is to minimize redundancy in Code. In this presentation, Sparkhound Consultant Ted Wagner shows how the MVP design pattern is used in SharePoint to create business models that can be reused easily between other ASP or C# application.
Neoito — Design patterns and depenedency injectionNeoito
Dependency injection is a software design pattern that allows someone to remove hard-coded dependencies and makes it possible to change them. Dependencies can be injected to the object via the constructor or via defined method or a setter property.
Faiz Mohamed Haneef is currently the CEO and Chief Technology Architect at Neoito. He's a former Architect at Lowe's, Hallmark and Infosys.
This is a Introduction to Object Oriented (OO) Concepts, Java Programming Language and leveraging Eclipse (IBM WebSphere) to develop Java applications.
This is based on JDK 1.4 concepts/features. A newer version maybe provided at a future date.
Through this presentation you will gain a good understanding of how the clean architecture pattern is implemented at Taxibeat. What issues the Android Taxibeat team has faced so far and what solutions we came up with. Of course, the benefits of clean architecture will also be discussed along with the way we managed to build two fast paced iterative apps that share functionality.
Developing Next-Gen Enterprise Web ApplicationMark Gu
Mark Gu, web architect from SunGard (Asset Finance), will be giving a presentation on how they are using ASP.NET MVC and various client-side technologies to develop their next generation Enterprise web application. The presentation will cover topics and promote discussions around pluggable websites, Knockout JS, Roslyn, code generation, and TypeScript just to name a few.
Connect 2014 - BP202: Rapid XPages Development Using the Application Layout C...Howard Greenberg
The Application Layout control may be the most useful and powerful tool available to an XPages developer. Learn how to enable and effectively use it to design a consistent user interface using IBM OneUI. Explore and compare several application layout design strategies using the application layout control. Understand how a well designed application layout can be used to provide a consistent design across all of your XPages applications and increase your XPages development productivity. See how the Bootstrap4XPages OpenNTF project can be used to with the application layout control to provide a responsive design for desktop, tablet and mobile devices using Twitter Bootstrap.
Speakers: Howard Greenberg and Paul Della-Nebbia from TLCC
Actively looking for an opportunity to work as a challenging Dot Net DeveloperKarthik Reddy
The .Net Developer designs, modifies, develops, writes and implements software programming applications and components. Supports and/or installs software applications and components. Works from written specifications and pre-established guidelines to perform the functions of the job and maintains documentation of process flow.
Actively looking for an opportunity to work as a challenging Dot Net DeveloperKarthik Reddy
The .Net Developer designs, modifies, develops, writes and implements software programming applications and components. Supports and/or installs software applications and components. Works from written specifications and pre-established guidelines to perform the functions of the job and maintains documentation of process flow.
Any structure expected to stand the test of time and change needs a strong foundation! Software is no exception. Engineering your code to grow in a stable and effective way is critical to your ability to rapidly meet the growing demands of users, new features, technologies, and platform capabilities. Join us to obtain architect-level design patterns for use in your Apex code to keep it well factored, easy to maintain, and in line with platform best practices. You'll follow a Force.com interpretation of Martin Fowler's Enterprise Architecture Application patterns, and the practice of Separation of Concerns.
Graspan: A Big Data System for Big Code AnalysisAftab Hussain
We built a disk-based parallel graph system, Graspan, that uses a novel edge-pair centric computation model to compute dynamic transitive closures on very large program graphs.
We implement context-sensitive pointer/alias and dataflow analyses on Graspan. An evaluation of these analyses on large codebases such as Linux shows that their Graspan implementations scale to millions of lines of code and are much simpler than their original implementations.
These analyses were used to augment the existing checkers; these augmented checkers found 132 new NULL pointer bugs and 1308 unnecessary NULL tests in Linux 4.4.0-rc5, PostgreSQL 8.3.9, and Apache httpd 2.2.18.
- Accepted in ASPLOS ‘17, Xi’an, China.
- Featured in the tutorial, Systemized Program Analyses: A Big Data Perspective on Static Analysis Scalability, ASPLOS ‘17.
- Invited for presentation at SoCal PLS ‘16.
- Invited for poster presentation at PLDI SRC ‘16.
Quarkus Hidden and Forbidden ExtensionsMax Andersen
Quarkus has a vast extension ecosystem and is known for its subsonic and subatomic feature set. Some of these features are not as well known, and some extensions are less talked about, but that does not make them less interesting - quite the opposite.
Come join this talk to see some tips and tricks for using Quarkus and some of the lesser known features, extensions and development techniques.
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
Hand Rolled Applicative User ValidationCode KataPhilip Schwarz
Could you use a simple piece of Scala validation code (granted, a very simplistic one too!) that you can rewrite, now and again, to refresh your basic understanding of Applicative operators <*>, <*, *>?
The goal is not to write perfect code showcasing validation, but rather, to provide a small, rough-and ready exercise to reinforce your muscle-memory.
Despite its grandiose-sounding title, this deck consists of just three slides showing the Scala 3 code to be rewritten whenever the details of the operators begin to fade away.
The code is my rough and ready translation of a Haskell user-validation program found in a book called Finding Success (and Failure) in Haskell - Fall in love with applicative functors.
Takashi Kobayashi and Hironori Washizaki, "SWEBOK Guide and Future of SE Education," First International Symposium on the Future of Software Engineering (FUSE), June 3-6, 2024, Okinawa, Japan
Artificia Intellicence and XPath Extension FunctionsOctavian Nadolu
The purpose of this presentation is to provide an overview of how you can use AI from XSLT, XQuery, Schematron, or XML Refactoring operations, the potential benefits of using AI, and some of the challenges we face.
Enterprise Resource Planning System includes various modules that reduce any business's workload. Additionally, it organizes the workflows, which drives towards enhancing productivity. Here are a detailed explanation of the ERP modules. Going through the points will help you understand how the software is changing the work dynamics.
To know more details here: https://blogs.nyggs.com/nyggs/enterprise-resource-planning-erp-system-modules/
GraphSummit Paris - The art of the possible with Graph TechnologyNeo4j
Sudhir Hasbe, Chief Product Officer, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeAftab Hussain
Understanding variable roles in code has been found to be helpful by students
in learning programming -- could variable roles help deep neural models in
performing coding tasks? We do an exploratory study.
- These are slides of the talk given at InteNSE'23: The 1st International Workshop on Interpretability and Robustness in Neural Software Engineering, co-located with the 45th International Conference on Software Engineering, ICSE 2023, Melbourne Australia
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. It’s here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
Software Engineering, Software Consulting, Tech Lead, Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Transaction, Spring MVC, OpenShift Cloud Platform, Kafka, REST, SOAP, LLD & HLD.
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...kalichargn70th171
A dynamic process unfolds in the intricate realm of software development, dedicated to crafting and sustaining products that effortlessly address user needs. Amidst vital stages like market analysis and requirement assessments, the heart of software development lies in the meticulous creation and upkeep of source code. Code alterations are inherent, challenging code quality, particularly under stringent deadlines.
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Crescat
Crescat is industry-trusted event management software, built by event professionals for event professionals. Founded in 2017, we have three key products tailored for the live event industry.
Crescat Event for concert promoters and event agencies. Crescat Venue for music venues, conference centers, wedding venues, concert halls and more. And Crescat Festival for festivals, conferences and complex events.
With a wide range of popular features such as event scheduling, shift management, volunteer and crew coordination, artist booking and much more, Crescat is designed for customisation and ease-of-use.
Over 125,000 events have been planned in Crescat and with hundreds of customers of all shapes and sizes, from boutique event agencies through to international concert promoters, Crescat is rigged for success. What's more, we highly value feedback from our users and we are constantly improving our software with updates, new features and improvements.
If you plan events, run a venue or produce festivals and you're looking for ways to make your life easier, then we have a solution for you. Try our software for free or schedule a no-obligation demo with one of our product specialists today at crescat.io
Code reviews are vital for ensuring good code quality. They serve as one of our last lines of defense against bugs and subpar code reaching production.
Yet, they often turn into annoying tasks riddled with frustration, hostility, unclear feedback and lack of standards. How can we improve this crucial process?
In this session we will cover:
- The Art of Effective Code Reviews
- Streamlining the Review Process
- Elevating Reviews with Automated Tools
By the end of this presentation, you'll have the knowledge on how to organize and improve your code review proces
7. BusinessSolutions
SoftwareEngineering
24.02.2009 7
„What is Design? It’s where you stand with a foot in two
worlds – the world of technology and the world of people
and human purposes – and you try to bring the two
together.”
MITCHELL KAPOR
8. BusinessSolutions
SoftwareEngineering
24.02.2009 8
Data Driven Design
How to design your system?
– Data-driven or domain-centric
Build your system around the data
Database first
Then mimick in .NET
Great MS tool support
10. BusinessSolutions
SoftwareEngineering
24.02.2009 10
„In the past, I'd frequently get pissed off with clients.
They were annoying, didn't know what they wanted and
always made the wrong choice.
Once I actually thought about it though, I realized that I
wasn't nearly as smart as I thought I was. The client
knew far more about his or her business than I did. Not
only that, but it was their money and my job was to
make them get the most out of it.
As the relationship turned more collaborative and
positive, not only did the end result greatly improve, but
programming became fun again.”
KARL SEGUIN
11. BusinessSolutions
SoftwareEngineering
24.02.2009 11
Users, Clients and Stakeholders
Client: pays the bill, should make decisions
about features and priorities, often User
User: uses System, different types
Stakeholders: anyone with a stake in the
system
Domain experts
12. BusinessSolutions
SoftwareEngineering
24.02.2009 12
Domain Objects
Find domain objects
Tool OOP (classes, encapsulation)
Domain experts business knowledge
Purpose of an enterprise developer
understand problem domain
Start with key noun words
Clients, Cars, Models, Packages, etc.
14. BusinessSolutions
SoftwareEngineering
24.02.2009 14
public class Car
{
private Model _model;
private List<Upgrade> _upgrades;
public void Add(Upgrade upgrade) { //todo }
}
public class Model
{
private int _id, _year;
private string _name;
public ReadOnlyCollection<Upgrade> GetAvailableUpgrades()
{
return null; //todo
}
}
public class Upgrade
{
private int _id;
private string _name;
public ReadOnlyCollection<Upgrade> RequiredUpgrades
{
get { return null; //todo }
}
}
15. BusinessSolutions
SoftwareEngineering
24.02.2009 15
public class Car
{
private Model _model; //todo where to initialize this?
private List<Upgrade> _upgrades;
public void Add(Upgrade upgrade)
{
_upgrades.Add(upgrade);
}
public ReadOnlyCollection<Upgrade> MissingUpgradeDependencies()
{
List<Upgrade> missingUpgrades = new List<Upgrade>();
foreach (Upgrade upgrade in _upgrades)
{
foreach (Upgrade dependentUpgrade in
upgrade.RequiredUpgrades)
{
if (!_upgrades.Contains(dependentUpgrade)
&& !missingUpgrades.Contains(dependentUpgrade))
{
missingUpgrades.Add(dependentUpgrade);
}
}
}
return missingUpgrades.AsReadOnly();
}
}
16. BusinessSolutions
SoftwareEngineering
24.02.2009 16
UI
Domain is presentation layer independent
don‘t mix presentation and domain logic !
Cohesive code focus on one thing
– Redirect to another page
– Display error messages
– Request additional information
– NO DOMAIN FUNCTIONALITY !
Code in codebehind will violate DRY
18. BusinessSolutions
SoftwareEngineering
24.02.2009 18
Tips & Tricks: Factory Pattern
public class Car
{
private Model _model;
private List<Upgrade> _upgrades;
private Car()
{
_upgrades = new List<Upgrade>();
}
public static Car CreateCar(Model model)
{
Car car = new Car();
car._model = model;
return car;
}
}
19. BusinessSolutions
SoftwareEngineering
24.02.2009 19
Factory Pattern: Advantages
We can return a null object
Chance to provide more meaningful function
names
User.CreateByCredentials(string username, string password)
User.CreateById(int id)
User.GetUsersByRole(string role)
23. BusinessSolutions
SoftwareEngineering
24.02.2009 23
Tips & Tricks: Interfaces
internal class SqlServerDataAccess : IDataAccess
{
public List<Upgrade> RetrieveAllUpgrades()
{
return null; //todo implement
}
}
public class Sample
{
public void ASampleMethod()
{
private IDataAccess da = DataAccess.CreateInstance();
private List<Upgrade> upgrades = da.RetrieveAllUpgrades();
}
}
24. BusinessSolutions
SoftwareEngineering
24.02.2009 24
Tips & Tricks:
Information Hiding & Encapsulation
Hide design decisions from other components
Implentation changes without impact
Example
– Private fields with public properties
37. BusinessSolutions
SoftwareEngineering
24.02.2009 37
„I would say that modern software engineering is the
ongoing refinement of the ever-increasing degrees of
decoupling. Yet, while the history of software shows that
coupling is bad, it also suggests that coupling is
unavoidable. An absolutely decoupled application is
useless because it adds no value. Developers can only
add value by coupling things together. The very act of
writing code is coupling one thing to another. The real
question is how to wisely choose what to be coupled to.”
JUVAL LÖWY
38. BusinessSolutions
SoftwareEngineering
24.02.2009 38
Decoupling
Layering to provide extensibility
– Different databases
– Different frontends
– YAGNI ?
Layering as result of cohesive and decoupled
code
Decoupling = key ingredient in writing testable
code
1. Coupling/Decoupling
2. Unit Testing
40. BusinessSolutions
SoftwareEngineering
24.02.2009 40
public class Car
{
private int _id;
public void Save()
{
if (!IsValid())
{
//todo: come up with a better exception
throw new InvalidOperationException("Car must be in valid
state");
}
if (_id == 0)
{
_id = DataAccess.CreateInstance().Save(this);
}
else
{
DataAccess.CreateInstance().Update(this);
}
}
private bool IsValid()
{
//todo: make sure the object is in a valid state
return true;
}
}
41. BusinessSolutions
SoftwareEngineering
24.02.2009 41
public class Car
{
private int _id;
public void Save()
{
if (!IsValid())
{
//todo: come up with a better exception
throw new InvalidOperationException("Car must be in valid
state");
}
if (_id == 0)
{
_id = DataAccess.CreateInstance().Save(this);
}
else
{
DataAccess.CreateInstance().Update(this);
}
}
private bool IsValid()
{
//todo: make sure the object is in a valid state
return true;
}
}
1. Make sure the correct exception is thrown when we try
to save a car which is in an invalid state,
2. Make sure the data access’ Save method is called
when it’s a new car, and
3. Make sure the Update method is called when it’s an
existing car.
Functionality of IsValid, Save and Update should
not be tested!
43. BusinessSolutions
SoftwareEngineering
24.02.2009 43
Don‘t avoid coupling like the Plague
string site = "CodeBetter";
Coupled to System.String
Coupling isn‘t always bad
But, no coupling to external components, code
that requires extensive setup or generates
random output
45. BusinessSolutions
SoftwareEngineering
24.02.2009 45
Constructor Injection
internal interface IDataAccess
{
int Save(Car car);
void Update(Car car);
}
internal class MockDataAccess : IDataAccess
{
private readonly List<Car> _cars = new List<Car>();
public int Save(Car car)
{
_cars.Add(car);
return _cars.Count;
}
public void Update(Car car)
{
_cars[_cars.IndexOf(car)] = car;
}
}
46. BusinessSolutions
SoftwareEngineering
24.02.2009 46
public class Car
{
private int _id;
private IDataAccess _dataProvider;
public Car() : this(new SqlServerDataAccess()) {}
internal Car(IDataAccess dataProvider) {
_dataProvider = dataProvider;
}
public void Save() {
if (!IsValid()) {
//todo: come up with a better exception
throw new InvalidOperationException("Car must be in valid
state");
}
if (_id == 0) {
_id = _dataProvider.Save(this);
}
else {
_dataProvider.Update(this);
}
}
}
50. BusinessSolutions
SoftwareEngineering
24.02.2009 50
DI with StructureMap
Constructor Injection removed
public class Car
{
private int _id;
public void Save()
{
if (!IsValid())
{
//todo: come up with a better exception
throw new InvalidOperationException("The car must be in a valid
state");
}
IDataAccess dataAccess = ObjectFactory.GetInstance<IDataAccess>();
if (_id == 0)
{
_id = dataAccess.Save(this);
}
else
{
dataAccess.Update(this);
}
}
}
51. BusinessSolutions
SoftwareEngineering
24.02.2009 51
Inject a Mock
public void AlmostATest()
{
ObjectFactory.InjectStub(typeof(IDataAccess), new
MockDataAccess());
Car car = new Car();
car.Save();
if (car.Id != 1)
{
//something went wrong
}
ObjectFactory.ResetDefaults();
}
56. BusinessSolutions
SoftwareEngineering
24.02.2009 56
Why unit testing
Improved quality
but more than that
Easier to change, maintain the system
Better design
„TDD isn't about testing because you're not
thinking as a tester when doing TDD – you’re
thinking as a designer.”
SCOTT BELLWARE
63. BusinessSolutions
SoftwareEngineering
24.02.2009 63
Mocking
Tested method often have dependencies
car.Save() database
Setup test database too complicated/slow
We want to test only if Save() interacts properly
with DAL
DAL will be tested separately
65. BusinessSolutions
SoftwareEngineering
24.02.2009 65
Mock – Test example
[TestFixture]
public class CarTest
{
[Test]
public void SaveCarCallsUpdateWhenAlreadyExistingCar()
{
MockRepository mocks = new MockRepository();
IDataAccess dataAccess = mocks.CreateMock<IDataAccess>();
ObjectFactory.InjectStub(typeof(IDataAccess), dataAccess);
Car car = new Car();
dataAccess.Update(car);
mocks.ReplayAll();
car.Id = 32;
car.Save();
mocks.VerifyAll();
ObjectFactory.ResetDefaults();
}
}
66. BusinessSolutions
SoftwareEngineering
24.02.2009 66
Let it fail
[Test]
public void SaveCarCallsUpdateWhenAlreadyExistingCar()
{
MockRepository mocks = new MockRepository();
IDataAccess dataAccess = mocks.CreateMock<IDataAccess>();
ObjectFactory.InjectStub(typeof(IDataAccess), dataAccess);
Car car = new Car();
dataAccess.Update(car);
dataAccess.Update(car);
mocks.ReplayAll();
car.Id = 32;
car.Save();
mocks.VerifyAll();
ObjectFactory.ResetDefaults();
}
67. BusinessSolutions
SoftwareEngineering
24.02.2009 67
Check return values
[Test]
public void SaveCarCallsSaveWhenNew()
{
MockRepository mocks = new MockRepository();
IDataAccess dataAccess = mocks.CreateMock< IDataAccess>();
ObjectFactory.InjectStub(typeof(IDataAccess), dataAccess);
private Car car = new Car();
Expect.Call(dataAccess.Save(car)).Return(389);
mocks.ReplayAll();
car.Save();
mocks.VerifyAll();
Assert.AreEqual(389, car.Id);
ObjectFactory.ResetDefaults();
}
68. BusinessSolutions
SoftwareEngineering
24.02.2009 68
Extract repetitive code
[TestFixture]
public class CarTest
{
private MockRepository _mocks;
private IDataAccess _dataAccess;
[SetUp]
public void SetUp()
{
_mocks = new MockRepository();
_dataAccess = _mocks.CreateMock<IDataAccess>();
ObjectFactory.InjectStub(typeof(IDataAccess), _dataAccess);
}
[TearDown]
public void TearDown()
{
_mocks.VerifyAll();
}
...
}
69. BusinessSolutions
SoftwareEngineering
24.02.2009 69
Test for exceptions
[TestFixture]
public class CarTest
{
...
[Test,
ExpectedException("CodeBetter.Foundations.PersistenceException")]
public void SaveCarCallsSaveWhenNew()
{
Car car = new Car();
Expect.Call(_dataAccess.Save(car)).Return(0);
_mocks.ReplayAll();
car.Save();
}
}
71. BusinessSolutions
SoftwareEngineering
24.02.2009 71
UI and Database Testing
ASP.NET Testing
– Very tight coupled
– Not easy/worth the effort to test
Data Access Layer Testing
– Possible & recommended
– Test-Database
– Use SetUp and TearDown to create a known state
75. BusinessSolutions
SoftwareEngineering
24.02.2009 75
NHibernate
Open-Source ORM framework
Complex
Completely transparent
– No base class, no decorator attributes
– Unit testing of domain layer possible
Maps domain objects to database objects
– Decouples code from specific DB implementation
78. BusinessSolutions
SoftwareEngineering
24.02.2009 78
Interacting with the database
private static ISessionFactory _sessionFactory;
public void Sample()
{
//Let's add a new car model
Model model = new Model();
model.Name = "Hummbee";
model.Description = "Great handling, built-in GPS to always find
your
way back home, Hummbee2Hummbe(tm)
communication";
model.Price = 50000.00;
ISession session = _sessionFactory.OpenSession();
session.Save(model);
//Let's discount the x149 model
IQuery query = session.CreateQuery("from Model model where
model.Name = ?");
Model model = query.SetString(0, "X149").UniqueResult<Model>();
model.Price -= 5000;
ISession session = _sessionFactory.OpenSession();
session.Update(model);
}
80. BusinessSolutions
SoftwareEngineering
24.02.2009 80
The other side of the relationship
private IList<Sale> _sales;
public IList<Sale> Sales
{
get { return _sales; }
}
<bag name="Sales" access="field.lowercase-underscore"
table="Sales" inverse="true" cascade="all">
<key column="SalesPersonId" />
<one-to-many class="Sale" />
</bag>
81. BusinessSolutions
SoftwareEngineering
24.02.2009 81
Querying
string lastName = "allen";
ISession session = _sessionFactory.OpenSession();
//retrieve a salesperson by last name
IQuery query = s.CreateQuery("from SalesPerson p where p.LastName =
'allen'");
SalesPerson p = query.UniqueResult<SalesPerson>();
//same as above but in 1 line, and with the last name as a variable
SalesPerson p = session.CreateQuery("from SalesPerson p where
p.LastName = ?").SetString(0, lastName).UniqueResult<SalesPerson>();
//people with few sales
IList<SalesPerson> slackers = session.CreateQuery("from SalesPerson
person where size(person.Sales) < 5").List<SalesPerson>();
85. BusinessSolutions
SoftwareEngineering
24.02.2009 85
Wrapping it up
The most flexible solution is the simplest.
– YAGNI, DRY, KISS and explicitness.
Coupling is unavoidable, but must be
minimized.
– The more dependencies you have, the harder your
code is to change.
– Unit Tests are the path to mastering low-coupling.
Badly coupled code will be impossible to test.
86. BusinessSolutions
SoftwareEngineering
24.02.2009 86
Wrapping it up
Higher quality should be good enough reason
to write tests, but, there are better reasons.
– Testing helps you identify bad coupling.
– Testing helps you find awkwardness in your API.
– Testing helps you document behavior and
expectations.
– Testing lets you make small and radical changes
with far greater confidence and far less risk.
87. BusinessSolutions
SoftwareEngineering
24.02.2009 87
Wrapping it up
It's possible to build successful software
without being Agile - but it's far less likely and a
lot less fun.
– ongoing customer collaboration
– iterative development
– No signed off specifications before starting to
develop
88. BusinessSolutions
SoftwareEngineering
24.02.2009 88
References
Foundations of Programming, Karl Seguin
http://codebetter.com/blogs/karlseguin/archive/2008
/06/24/foundations-of-programming-ebook.aspx
with additional topics
– Back to Basics: Memory
– Back to Basics: Exceptions
– Back to Basics: Proxy This and
Proxy That