SlideShare a Scribd company logo
Thin Controllers -
Fat models
How to write better code
- MVC -
Adapted by
Dr. Syed Hassan Amin
Introduction
• MVC is one of the most common design
patterns
• It is used in Android, iOS and web
applications.
• Most developers are confident about having
good, practical knowledge of this pattern.
• MVC pattern is perhaps the most abused
design pattern.
Points to Ponder
• What is anti-pattern ?
• What is dumb data holder ?
Fat Controller Anti Pattern
• The anti pattern that identifies misuse of MVC
pattern is Fat controller.
• Fat controller has overly complex logic and
domain concepts.
• Domain logic should be completely separate from
controllers so that it can be easily extended, and
reused.
• Putting domain concepts in controller stinks, and
results in strong coupling between domain logic,
controllers and view.

Recommended for you

Micro frontend
Micro frontendMicro frontend
Micro frontend

There is no doubt that one of the most emerging terms in today Tech Community is MicroFront end Architecture, in this Lecture, we will go through the Basics of Micro-FrontEnd Architecture Concept, and will discuss with Examples, How some techniques to implement it, Also will discuss if its suitable for you to migrate from old single Front-End App to Micro-FrontEnd Architecture.

frontendangularjsjavascript
Micro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - PlansoftMicro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - Plansoft

A presentation to explain the microservices architecture, the pro and the cons, with a view on how to migrate from a monolith to a SOA architecture. Also, we'll show the benefits of the microservices architecture also for the frontend side with the microfrontend architecture.

microservicesmicrofrontenddocker
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices

The document provides an overview of microservices architecture including: - Definitions and characteristics of microservices such as componentization via services, decentralized governance, and infrastructure automation. - Common drivers for adopting microservices like agility, safety, and scalability. - Guidelines for decomposing monolithic applications into microservices based on business capabilities and domain-driven design. - Discussion of differences between microservices and service-oriented architecture (SOA). - Ecosystem of tools involved in microservices including development frameworks, APIs, databases, containers, and service meshes. - Common design patterns and anti-patterns when developing microservices.

microservicessyntoucharchitecture
WARNING: Do not try it at home/work!
The WRONG way - "mvC"
mvC - Controller
● Whole business logic in a Controller.
Controller:
I'll do everything for you.
You can keep everything in one place.
That's so simple!
mvC - Model
• Models used basically just to store data in
database.
• Model
– I'm just a data so why should I do anything more
than just exist?
mvC - View
• View uses the database directly
• Just give me database connection and I'll do
everything!
• View
– Give me more power and you won't need
controllers and models at all!

Recommended for you

An introduction to Microservices
An introduction to MicroservicesAn introduction to Microservices
An introduction to Microservices

This document provides an introduction to microservices architecture. It discusses why companies adopt the microservices style, how to design microservices, common patterns, and examples from Netflix. The key points are: 1) Microservices architecture breaks applications into small, independent services that communicate over well-defined interfaces. This improves modularity, scalability, and allows independent deployments. 2) When designing microservices, services should be organized around business capabilities, have decentralized governance and data, and be designed to fail independently through patterns like circuit breakers. 3) Netflix is a leader in microservices and has open sourced many tools like Hystrix for latency handling and Eureka for service discovery that

architecturemicroservicesnetflix
Introducing Clean Architecture
Introducing Clean ArchitectureIntroducing Clean Architecture
Introducing Clean Architecture

There's another talk about Clean Architecture, SOLID, and our approach at InfoJobs. If you need the slides, don't hesitate to fork https://github.com/schibsted-android-training/workshop-5

clean architecturesolidinfojobs
Composable Software Architecture with Spring
Composable Software Architecture with SpringComposable Software Architecture with Spring
Composable Software Architecture with Spring

Sam Brannen gave a presentation on composable software architecture with Spring. He discussed how modern enterprise applications need to interact with multiple external systems and services. A composable architecture uses modular, stateless components that can be assembled in different combinations. Spring supports this through features like dependency injection, inversion of control, and its ecosystem of projects. The roadmap for Spring 4.0 includes better support for Java 8, configuring Spring with Groovy, and key Java EE 7 technologies.

architecturespringjava
mvC - problems?
● Copy/Paste to "reuse" the code.
● Long and complex methods (actions) that
need to be copied in order to use
polymorphism.
● Very difficult to test.
You will pay for mvC
Makes your life easier
The RIGHT way - MVC
MVC - Controller
● Just a translator for a user wishes (request)
so model and view can understand and
respond in proper way (response).
Controller:
I should be so thin you should barely notice me.
I'll just tell model what user did and the view to show what
he wants - facade for business logic.

Recommended for you

Learning solid principles using c#
Learning solid principles using c#Learning solid principles using c#
Learning solid principles using c#

Learning solid principles using c# S Single Responsibility Principle O Open Closed Principle L Liskovs Substitution Principle I Interface Segregation Principle D Dependency Inversion principle

open closed principledependency inversion principlesingle responsibility principle
Effective API Gateway
Effective API GatewayEffective API Gateway
Effective API Gateway

The document discusses the benefits of using an API gateway to handle communication between client applications and microservices, rather than direct client-to-microservice communication. It notes that an API gateway can reduce coupling between clients and services, minimize round trips for client requests, centralize security handling, and help mitigate deployment risks. However, it cautions that the API gateway should not act as a single aggregator and should be segregated based on business boundaries to avoid violating microservice autonomy. Examples of open source and paid API gateway tools and implementations are also provided.

api gatewayapiazure api management
CQRS and event sourcing
CQRS and event sourcingCQRS and event sourcing
CQRS and event sourcing

The document discusses CQRS (Command Query Responsibility Segregation) and event sourcing. It begins by explaining that most applications are built with CRUD as the main paradigm, which can cause the user intent to get lost. It advocates shifting the focus from pure data towards intent and process automation. This means changing from CRUD-style application design where the process was implicit. It discusses capturing user intent at the UI through task-based styles rather than CRUD styles. Commands are presented as a way to capture user intent in a prescriptive manner. The document provides examples of commands and events and how they relate to domain events and synchronizing read and write models to support queries.

cqrsdddevents
MVC - Model
● This is where whole "magic" should happen.
● Model should store and manipulate data.
● It should be used intensively by controllers to
do what user requested and by views to
show data user wants to see.
● Business logic should be in models, eg.
"$ageLimit > 20".
Model:
I'm the proper guy for doing the hard work.
I know how your app should work and why.
MVC - View
● Gets a model or a collection of models
selected by controller (according to user
request) and shows it.
● It tells the controller what user has done and
what does he expect to happen.
View:
I'll show you what you want and let you do cool things with
models.
MVC - Action helper
● Easy and good way to reuse code between
controllers.
● Thanks to models it's using it keeps things
DRY.
● Prefer action helper over methods put in
controllers extended by other controllers.
Action helper:
I can do common things with the models according to the
request. I'm the controllers ... helper.
MVC - View helper
● Helps you render HTML template that you
use on many views.
View helper:
I can help you make things (php, js and html code) look
nice.

Recommended for you

OutSystems Tips and Tricks
OutSystems Tips and TricksOutSystems Tips and Tricks
OutSystems Tips and Tricks

When setting up a new project we have some tips and tricks to help you do this in the best way possible, incl. infrastructure, database, standard attributes, logging, code alignment, and service center.

low-codelow code platformslow-code development
A pattern language for microservices - June 2021
A pattern language for microservices - June 2021 A pattern language for microservices - June 2021
A pattern language for microservices - June 2021

The microservice architecture is growing in popularity. It is an architectural style that structures an application as a set of loosely coupled services that are organized around business capabilities. Its goal is to enable the continuous delivery of large, complex applications. However, the microservice architecture is not a silver bullet and it has some significant drawbacks. The goal of the microservices pattern language is to enable software developers to apply the microservice architecture effectively. It is a collection of patterns that solve architecture, design, development and operational problems. In this talk, I’ll provide an overview of the microservice architecture and describe the motivations for the pattern language. You will learn about the key patterns in the pattern language.

microservicesmicroservice architecturepattern language
Micro frontend architecture_presentation_ssoni
Micro frontend architecture_presentation_ssoniMicro frontend architecture_presentation_ssoni
Micro frontend architecture_presentation_ssoni

This document discusses micro frontends, which is a microservices approach to front end web development. It outlines some issues with monolithic frontends like scaling and communication problems. It then discusses micro frontend design principles such as autonomous features, team ownership, being tech agnostic, driving value, and following microservices patterns. Finally, it covers techniques for implementing micro frontends including using separate or shared runtimes with options like micro apps, iframes, or webpack modular federation and integrating them through runtime, build time, or iframe methods.

frontendmicro frontendreactjs
OOP - Model
● If you think you're using OOP because you
have classes - you are wrong!
● "Happy" object should have just one
responsibility.
"Fat model" does not mean it has to have
hundred lines of code.
● Object should be easy to test. You should be
able to "mock" things it's using.
● Let object be dependent - inject into it the
things it needs.
MVC- Web Applications
• When developing web applications, there are many traps regarding
use of controllers :
– Controller per Page : In this case you will end up creating too many
controllers. However, controllers can handle more than one page.
– Controller per Entity : This approach is too granular and may become
even more challenging when we have more than one entity per view.
Rails and Code Ignitor have this sort of controller per model approach.
• It is advisable to write single test class per controller and prefer
using MVC pattern. PHP OOP provides great functionality to avoid
tight coupling.
MVC - JavaScript
● All those rules applies to JavaScript and
other languages.
● JavaScript code is also great when you use
MVC!
So you should/could have:
MV(JS: MVC)C
Zend Framework uses MVC - really?
● It's not a "true" MVC.
● MVC was designed for desktop apps.
● It has many "branches".
@see MVP
@see Model2 ("MVC for web apps")

Recommended for you

MVVM
MVVMMVVM
MVVM

This document provides an overview of the Model-View-ViewModel (MVVM) design pattern. It defines MVVM as splitting the user interface into three components: the Model contains the application's data; the View displays the data and handles user input; and the ViewModel acts as a mediator between the Model and View. The document discusses WPF concepts like bindings and data templates that enable MVVM. It notes advantages like testability and separation of concerns, and disadvantages like potential overhead. Examples are provided and references for further reading.

mvcdesign patternswcf
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID

A presentation about Clean Code, SOLID, painless continuous development and how to survive under a snowdrift of code

#ios#it#indeema
CQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility SegregationCQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility Segregation

This document discusses Command Query Responsibility Segregation (CQRS), a pattern for building scalable, multi-user systems. CQRS separates commands and queries by using different models for updates and reads. This allows optimization of read and write operations independently to improve scalability. The document outlines common CQRS components like commands, events, and persistent view models, and provides guidelines for when to use CQRS, such as for large, distributed systems with complex business logic.

cqrsdddevent sourcing
Questions

More Related Content

What's hot

Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservices
Anil Allewar
 
DevOps topologies
DevOps topologiesDevOps topologies
DevOps topologies
Sushma
 
Building event-driven (Micro)Services with Apache Kafka
Building event-driven (Micro)Services with Apache KafkaBuilding event-driven (Micro)Services with Apache Kafka
Building event-driven (Micro)Services with Apache Kafka
Guido Schmutz
 
Micro frontend
Micro frontendMicro frontend
Micro frontend
Amr Abd El Latief
 
Micro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - PlansoftMicro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - Plansoft
Miki Lombardi
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
Roger van de Kimmenade
 
An introduction to Microservices
An introduction to MicroservicesAn introduction to Microservices
An introduction to Microservices
Cisco DevNet
 
Introducing Clean Architecture
Introducing Clean ArchitectureIntroducing Clean Architecture
Introducing Clean Architecture
Roc Boronat
 
Composable Software Architecture with Spring
Composable Software Architecture with SpringComposable Software Architecture with Spring
Composable Software Architecture with Spring
Sam Brannen
 
Learning solid principles using c#
Learning solid principles using c#Learning solid principles using c#
Learning solid principles using c#
Aditya Kumar Rajan
 
Effective API Gateway
Effective API GatewayEffective API Gateway
Effective API Gateway
Hari Wiz
 
CQRS and event sourcing
CQRS and event sourcingCQRS and event sourcing
CQRS and event sourcing
Jeppe Cramon
 
OutSystems Tips and Tricks
OutSystems Tips and TricksOutSystems Tips and Tricks
OutSystems Tips and Tricks
OutSystems
 
A pattern language for microservices - June 2021
A pattern language for microservices - June 2021 A pattern language for microservices - June 2021
A pattern language for microservices - June 2021
Chris Richardson
 
Micro frontend architecture_presentation_ssoni
Micro frontend architecture_presentation_ssoniMicro frontend architecture_presentation_ssoni
Micro frontend architecture_presentation_ssoni
Sandeep Soni
 
MVVM
MVVMMVVM
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID
Indeema Software Inc.
 
CQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility SegregationCQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility Segregation
Brian Ritchie
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
Guillaume Collic
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
Amazon Web Services
 

What's hot (20)

Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservices
 
DevOps topologies
DevOps topologiesDevOps topologies
DevOps topologies
 
Building event-driven (Micro)Services with Apache Kafka
Building event-driven (Micro)Services with Apache KafkaBuilding event-driven (Micro)Services with Apache Kafka
Building event-driven (Micro)Services with Apache Kafka
 
Micro frontend
Micro frontendMicro frontend
Micro frontend
 
Micro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - PlansoftMicro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - Plansoft
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
An introduction to Microservices
An introduction to MicroservicesAn introduction to Microservices
An introduction to Microservices
 
Introducing Clean Architecture
Introducing Clean ArchitectureIntroducing Clean Architecture
Introducing Clean Architecture
 
Composable Software Architecture with Spring
Composable Software Architecture with SpringComposable Software Architecture with Spring
Composable Software Architecture with Spring
 
Learning solid principles using c#
Learning solid principles using c#Learning solid principles using c#
Learning solid principles using c#
 
Effective API Gateway
Effective API GatewayEffective API Gateway
Effective API Gateway
 
CQRS and event sourcing
CQRS and event sourcingCQRS and event sourcing
CQRS and event sourcing
 
OutSystems Tips and Tricks
OutSystems Tips and TricksOutSystems Tips and Tricks
OutSystems Tips and Tricks
 
A pattern language for microservices - June 2021
A pattern language for microservices - June 2021 A pattern language for microservices - June 2021
A pattern language for microservices - June 2021
 
Micro frontend architecture_presentation_ssoni
Micro frontend architecture_presentation_ssoniMicro frontend architecture_presentation_ssoni
Micro frontend architecture_presentation_ssoni
 
MVVM
MVVMMVVM
MVVM
 
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID
 
CQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility SegregationCQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility Segregation
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 

Similar to Thin Controllers Fat Models - How to Write Better Code

Ps02 cint24 mvc in php
Ps02 cint24 mvc in phpPs02 cint24 mvc in php
Ps02 cint24 mvc in php
Conestoga Collage
 
RubyConf Bangladesh 2017 - Rails buggy code
RubyConf Bangladesh 2017 - Rails buggy codeRubyConf Bangladesh 2017 - Rails buggy code
RubyConf Bangladesh 2017 - Rails buggy code
Ruby Bangladesh
 
MVC architecture in software programming for interactive apps
MVC architecture in software programming for interactive appsMVC architecture in software programming for interactive apps
MVC architecture in software programming for interactive apps
KotiTenali
 
Web engineering - MVC
Web engineering - MVCWeb engineering - MVC
Web engineering - MVC
Nosheen Qamar
 
Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
Codemotion
 
Real World AngularJS recipes: beyond TodoMVC
Real World AngularJS recipes: beyond TodoMVCReal World AngularJS recipes: beyond TodoMVC
Real World AngularJS recipes: beyond TodoMVC
Carlo Bonamico
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncube
Malisa Ncube
 
Lecture 05 - Creating a website with Razor Pages.pdf
Lecture 05 - Creating a website with Razor Pages.pdfLecture 05 - Creating a website with Razor Pages.pdf
Lecture 05 - Creating a website with Razor Pages.pdf
Lê Thưởng
 
MVC architecture
MVC architectureMVC architecture
MVC.pptx
MVC.pptxMVC.pptx
MVC.pptx
HassanAliKhan36
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
Qamar Abbas
 
Module2
Module2Module2
Module2
Hoàng Lê
 
Introduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumarIntroduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumar
Appfinz Technologies
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
Manish Shekhawat
 
Introduction to Angular Js
Introduction to Angular JsIntroduction to Angular Js
Introduction to Angular Js
Professional Guru
 
Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01
Jennie Gajjar
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
ravindraquicsolv
 
Principles of MVC for PHP Developers
Principles of MVC for PHP DevelopersPrinciples of MVC for PHP Developers
Principles of MVC for PHP Developers
Edureka!
 
реалии использования Mv в i os разработке
реалии использования Mv в i os разработкереалии использования Mv в i os разработке
реалии использования Mv в i os разработке
Provectus
 
Adopting MVVM
Adopting MVVMAdopting MVVM
Adopting MVVM
John Cumming
 

Similar to Thin Controllers Fat Models - How to Write Better Code (20)

Ps02 cint24 mvc in php
Ps02 cint24 mvc in phpPs02 cint24 mvc in php
Ps02 cint24 mvc in php
 
RubyConf Bangladesh 2017 - Rails buggy code
RubyConf Bangladesh 2017 - Rails buggy codeRubyConf Bangladesh 2017 - Rails buggy code
RubyConf Bangladesh 2017 - Rails buggy code
 
MVC architecture in software programming for interactive apps
MVC architecture in software programming for interactive appsMVC architecture in software programming for interactive apps
MVC architecture in software programming for interactive apps
 
Web engineering - MVC
Web engineering - MVCWeb engineering - MVC
Web engineering - MVC
 
Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
 
Real World AngularJS recipes: beyond TodoMVC
Real World AngularJS recipes: beyond TodoMVCReal World AngularJS recipes: beyond TodoMVC
Real World AngularJS recipes: beyond TodoMVC
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncube
 
Lecture 05 - Creating a website with Razor Pages.pdf
Lecture 05 - Creating a website with Razor Pages.pdfLecture 05 - Creating a website with Razor Pages.pdf
Lecture 05 - Creating a website with Razor Pages.pdf
 
MVC architecture
MVC architectureMVC architecture
MVC architecture
 
MVC.pptx
MVC.pptxMVC.pptx
MVC.pptx
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
 
Module2
Module2Module2
Module2
 
Introduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumarIntroduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumar
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Introduction to Angular Js
Introduction to Angular JsIntroduction to Angular Js
Introduction to Angular Js
 
Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
 
Principles of MVC for PHP Developers
Principles of MVC for PHP DevelopersPrinciples of MVC for PHP Developers
Principles of MVC for PHP Developers
 
реалии использования Mv в i os разработке
реалии использования Mv в i os разработкереалии использования Mv в i os разработке
реалии использования Mv в i os разработке
 
Adopting MVVM
Adopting MVVMAdopting MVVM
Adopting MVVM
 

More from Dr. Syed Hassan Amin

Greenplum versus redshift and actian vectorwise comparison
Greenplum versus redshift and actian vectorwise comparisonGreenplum versus redshift and actian vectorwise comparison
Greenplum versus redshift and actian vectorwise comparison
Dr. Syed Hassan Amin
 
Introduction To Docker
Introduction To  DockerIntroduction To  Docker
Introduction To Docker
Dr. Syed Hassan Amin
 
Laravel Unit Testing
Laravel Unit TestingLaravel Unit Testing
Laravel Unit Testing
Dr. Syed Hassan Amin
 
Multitier holistic Approach for urdu Nastaliq Recognition
Multitier holistic Approach for urdu Nastaliq RecognitionMultitier holistic Approach for urdu Nastaliq Recognition
Multitier holistic Approach for urdu Nastaliq Recognition
Dr. Syed Hassan Amin
 
Understandig PCA and LDA
Understandig PCA and LDAUnderstandig PCA and LDA
Understandig PCA and LDA
Dr. Syed Hassan Amin
 
Agile Scrum Methodology
Agile Scrum MethodologyAgile Scrum Methodology
Agile Scrum Methodology
Dr. Syed Hassan Amin
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
Dr. Syed Hassan Amin
 
Software Project Management Tips and Tricks
Software Project Management Tips and TricksSoftware Project Management Tips and Tricks
Software Project Management Tips and Tricks
Dr. Syed Hassan Amin
 
Improving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesImproving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design Principles
Dr. Syed Hassan Amin
 
Learning Technology Leadership from Steve Jobs
Learning Technology Leadership from Steve JobsLearning Technology Leadership from Steve Jobs
Learning Technology Leadership from Steve Jobs
Dr. Syed Hassan Amin
 
Understanding and Managing Technical Debt
Understanding and Managing Technical DebtUnderstanding and Managing Technical Debt
Understanding and Managing Technical Debt
Dr. Syed Hassan Amin
 
An OCR System for recognition of Urdu text in Nastaliq Font
An OCR System for recognition of Urdu text in Nastaliq FontAn OCR System for recognition of Urdu text in Nastaliq Font
An OCR System for recognition of Urdu text in Nastaliq Font
Dr. Syed Hassan Amin
 

More from Dr. Syed Hassan Amin (12)

Greenplum versus redshift and actian vectorwise comparison
Greenplum versus redshift and actian vectorwise comparisonGreenplum versus redshift and actian vectorwise comparison
Greenplum versus redshift and actian vectorwise comparison
 
Introduction To Docker
Introduction To  DockerIntroduction To  Docker
Introduction To Docker
 
Laravel Unit Testing
Laravel Unit TestingLaravel Unit Testing
Laravel Unit Testing
 
Multitier holistic Approach for urdu Nastaliq Recognition
Multitier holistic Approach for urdu Nastaliq RecognitionMultitier holistic Approach for urdu Nastaliq Recognition
Multitier holistic Approach for urdu Nastaliq Recognition
 
Understandig PCA and LDA
Understandig PCA and LDAUnderstandig PCA and LDA
Understandig PCA and LDA
 
Agile Scrum Methodology
Agile Scrum MethodologyAgile Scrum Methodology
Agile Scrum Methodology
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
 
Software Project Management Tips and Tricks
Software Project Management Tips and TricksSoftware Project Management Tips and Tricks
Software Project Management Tips and Tricks
 
Improving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesImproving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design Principles
 
Learning Technology Leadership from Steve Jobs
Learning Technology Leadership from Steve JobsLearning Technology Leadership from Steve Jobs
Learning Technology Leadership from Steve Jobs
 
Understanding and Managing Technical Debt
Understanding and Managing Technical DebtUnderstanding and Managing Technical Debt
Understanding and Managing Technical Debt
 
An OCR System for recognition of Urdu text in Nastaliq Font
An OCR System for recognition of Urdu text in Nastaliq FontAn OCR System for recognition of Urdu text in Nastaliq Font
An OCR System for recognition of Urdu text in Nastaliq Font
 

Recently uploaded

Ported to Cloud with Wing_ Blue ZnZone app from _Hexagonal Architecture Expla...
Ported to Cloud with Wing_ Blue ZnZone app from _Hexagonal Architecture Expla...Ported to Cloud with Wing_ Blue ZnZone app from _Hexagonal Architecture Expla...
Ported to Cloud with Wing_ Blue ZnZone app from _Hexagonal Architecture Expla...
Asher Sterkin
 
React Native vs Flutter - SSTech System
React Native vs Flutter  - SSTech SystemReact Native vs Flutter  - SSTech System
React Native vs Flutter - SSTech System
SSTech System
 
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...
karim wahed
 
A Comparative Analysis of Functional and Non-Functional Testing.pdf
A Comparative Analysis of Functional and Non-Functional Testing.pdfA Comparative Analysis of Functional and Non-Functional Testing.pdf
A Comparative Analysis of Functional and Non-Functional Testing.pdf
kalichargn70th171
 
NBFC Software: Optimize Your Non-Banking Financial Company
NBFC Software: Optimize Your Non-Banking Financial CompanyNBFC Software: Optimize Your Non-Banking Financial Company
NBFC Software: Optimize Your Non-Banking Financial Company
NBFC Softwares
 
Folding Cheat Sheet #7 - seventh in a series
Folding Cheat Sheet #7 - seventh in a seriesFolding Cheat Sheet #7 - seventh in a series
Folding Cheat Sheet #7 - seventh in a series
Philip Schwarz
 
Development of Chatbot Using AI\ML Technologies
Development of Chatbot Using AI\ML TechnologiesDevelopment of Chatbot Using AI\ML Technologies
Development of Chatbot Using AI\ML Technologies
MaisnamLuwangPibarel
 
Migrate your Infrastructure to the AWS Cloud
Migrate your Infrastructure to the AWS CloudMigrate your Infrastructure to the AWS Cloud
Migrate your Infrastructure to the AWS Cloud
Ortus Solutions, Corp
 
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTIONBITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
ssuser2b426d1
 
React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...
React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...
React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...
Semiosis Software Private Limited
 
WhatsApp Tracker - Tracking WhatsApp to Boost Online Safety.pdf
WhatsApp Tracker -  Tracking WhatsApp to Boost Online Safety.pdfWhatsApp Tracker -  Tracking WhatsApp to Boost Online Safety.pdf
WhatsApp Tracker - Tracking WhatsApp to Boost Online Safety.pdf
onemonitarsoftware
 
Leading Project Management Tool Taskruop.pptx
Leading Project Management Tool Taskruop.pptxLeading Project Management Tool Taskruop.pptx
Leading Project Management Tool Taskruop.pptx
taskroupseo
 
Intro to Amazon Web Services (AWS) and Gen AI
Intro to Amazon Web Services (AWS) and Gen AIIntro to Amazon Web Services (AWS) and Gen AI
Intro to Amazon Web Services (AWS) and Gen AI
Ortus Solutions, Corp
 
MVP Mobile Application - Codearrest.pptx
MVP Mobile Application - Codearrest.pptxMVP Mobile Application - Codearrest.pptx
MVP Mobile Application - Codearrest.pptx
Mitchell Marsh
 
Wired_2.0_Create_AmsterdamJUG_09072024.pptx
Wired_2.0_Create_AmsterdamJUG_09072024.pptxWired_2.0_Create_AmsterdamJUG_09072024.pptx
Wired_2.0_Create_AmsterdamJUG_09072024.pptx
SimonedeGijt
 
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdf
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdfAWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdf
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdf
karim wahed
 
ANSYS Mechanical APDL Introductory Tutorials.pdf
ANSYS Mechanical APDL Introductory Tutorials.pdfANSYS Mechanical APDL Introductory Tutorials.pdf
ANSYS Mechanical APDL Introductory Tutorials.pdf
sachin chaurasia
 
Addressing the Top 9 User Pain Points with Visual Design Elements.pptx
Addressing the Top 9 User Pain Points with Visual Design Elements.pptxAddressing the Top 9 User Pain Points with Visual Design Elements.pptx
Addressing the Top 9 User Pain Points with Visual Design Elements.pptx
Sparity1
 
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
ThousandEyes
 
CViewSurvey Digitech Pvt Ltd that works on a proven C.A.A.G. model.
CViewSurvey Digitech Pvt Ltd that  works on a proven C.A.A.G. model.CViewSurvey Digitech Pvt Ltd that  works on a proven C.A.A.G. model.
CViewSurvey Digitech Pvt Ltd that works on a proven C.A.A.G. model.
bhatinidhi2001
 

Recently uploaded (20)

Ported to Cloud with Wing_ Blue ZnZone app from _Hexagonal Architecture Expla...
Ported to Cloud with Wing_ Blue ZnZone app from _Hexagonal Architecture Expla...Ported to Cloud with Wing_ Blue ZnZone app from _Hexagonal Architecture Expla...
Ported to Cloud with Wing_ Blue ZnZone app from _Hexagonal Architecture Expla...
 
React Native vs Flutter - SSTech System
React Native vs Flutter  - SSTech SystemReact Native vs Flutter  - SSTech System
React Native vs Flutter - SSTech System
 
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) Course Introducti...
 
A Comparative Analysis of Functional and Non-Functional Testing.pdf
A Comparative Analysis of Functional and Non-Functional Testing.pdfA Comparative Analysis of Functional and Non-Functional Testing.pdf
A Comparative Analysis of Functional and Non-Functional Testing.pdf
 
NBFC Software: Optimize Your Non-Banking Financial Company
NBFC Software: Optimize Your Non-Banking Financial CompanyNBFC Software: Optimize Your Non-Banking Financial Company
NBFC Software: Optimize Your Non-Banking Financial Company
 
Folding Cheat Sheet #7 - seventh in a series
Folding Cheat Sheet #7 - seventh in a seriesFolding Cheat Sheet #7 - seventh in a series
Folding Cheat Sheet #7 - seventh in a series
 
Development of Chatbot Using AI\ML Technologies
Development of Chatbot Using AI\ML TechnologiesDevelopment of Chatbot Using AI\ML Technologies
Development of Chatbot Using AI\ML Technologies
 
Migrate your Infrastructure to the AWS Cloud
Migrate your Infrastructure to the AWS CloudMigrate your Infrastructure to the AWS Cloud
Migrate your Infrastructure to the AWS Cloud
 
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTIONBITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
 
React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...
React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...
React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...
 
WhatsApp Tracker - Tracking WhatsApp to Boost Online Safety.pdf
WhatsApp Tracker -  Tracking WhatsApp to Boost Online Safety.pdfWhatsApp Tracker -  Tracking WhatsApp to Boost Online Safety.pdf
WhatsApp Tracker - Tracking WhatsApp to Boost Online Safety.pdf
 
Leading Project Management Tool Taskruop.pptx
Leading Project Management Tool Taskruop.pptxLeading Project Management Tool Taskruop.pptx
Leading Project Management Tool Taskruop.pptx
 
Intro to Amazon Web Services (AWS) and Gen AI
Intro to Amazon Web Services (AWS) and Gen AIIntro to Amazon Web Services (AWS) and Gen AI
Intro to Amazon Web Services (AWS) and Gen AI
 
MVP Mobile Application - Codearrest.pptx
MVP Mobile Application - Codearrest.pptxMVP Mobile Application - Codearrest.pptx
MVP Mobile Application - Codearrest.pptx
 
Wired_2.0_Create_AmsterdamJUG_09072024.pptx
Wired_2.0_Create_AmsterdamJUG_09072024.pptxWired_2.0_Create_AmsterdamJUG_09072024.pptx
Wired_2.0_Create_AmsterdamJUG_09072024.pptx
 
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdf
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdfAWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdf
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdf
 
ANSYS Mechanical APDL Introductory Tutorials.pdf
ANSYS Mechanical APDL Introductory Tutorials.pdfANSYS Mechanical APDL Introductory Tutorials.pdf
ANSYS Mechanical APDL Introductory Tutorials.pdf
 
Addressing the Top 9 User Pain Points with Visual Design Elements.pptx
Addressing the Top 9 User Pain Points with Visual Design Elements.pptxAddressing the Top 9 User Pain Points with Visual Design Elements.pptx
Addressing the Top 9 User Pain Points with Visual Design Elements.pptx
 
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
 
CViewSurvey Digitech Pvt Ltd that works on a proven C.A.A.G. model.
CViewSurvey Digitech Pvt Ltd that  works on a proven C.A.A.G. model.CViewSurvey Digitech Pvt Ltd that  works on a proven C.A.A.G. model.
CViewSurvey Digitech Pvt Ltd that works on a proven C.A.A.G. model.
 

Thin Controllers Fat Models - How to Write Better Code

  • 1. Thin Controllers - Fat models How to write better code - MVC - Adapted by Dr. Syed Hassan Amin
  • 2. Introduction • MVC is one of the most common design patterns • It is used in Android, iOS and web applications. • Most developers are confident about having good, practical knowledge of this pattern. • MVC pattern is perhaps the most abused design pattern.
  • 3. Points to Ponder • What is anti-pattern ? • What is dumb data holder ?
  • 4. Fat Controller Anti Pattern • The anti pattern that identifies misuse of MVC pattern is Fat controller. • Fat controller has overly complex logic and domain concepts. • Domain logic should be completely separate from controllers so that it can be easily extended, and reused. • Putting domain concepts in controller stinks, and results in strong coupling between domain logic, controllers and view.
  • 5. WARNING: Do not try it at home/work! The WRONG way - "mvC"
  • 6. mvC - Controller ● Whole business logic in a Controller. Controller: I'll do everything for you. You can keep everything in one place. That's so simple!
  • 7. mvC - Model • Models used basically just to store data in database. • Model – I'm just a data so why should I do anything more than just exist?
  • 8. mvC - View • View uses the database directly • Just give me database connection and I'll do everything! • View – Give me more power and you won't need controllers and models at all!
  • 9. mvC - problems? ● Copy/Paste to "reuse" the code. ● Long and complex methods (actions) that need to be copied in order to use polymorphism. ● Very difficult to test.
  • 10. You will pay for mvC
  • 11. Makes your life easier The RIGHT way - MVC
  • 12. MVC - Controller ● Just a translator for a user wishes (request) so model and view can understand and respond in proper way (response). Controller: I should be so thin you should barely notice me. I'll just tell model what user did and the view to show what he wants - facade for business logic.
  • 13. MVC - Model ● This is where whole "magic" should happen. ● Model should store and manipulate data. ● It should be used intensively by controllers to do what user requested and by views to show data user wants to see. ● Business logic should be in models, eg. "$ageLimit > 20". Model: I'm the proper guy for doing the hard work. I know how your app should work and why.
  • 14. MVC - View ● Gets a model or a collection of models selected by controller (according to user request) and shows it. ● It tells the controller what user has done and what does he expect to happen. View: I'll show you what you want and let you do cool things with models.
  • 15. MVC - Action helper ● Easy and good way to reuse code between controllers. ● Thanks to models it's using it keeps things DRY. ● Prefer action helper over methods put in controllers extended by other controllers. Action helper: I can do common things with the models according to the request. I'm the controllers ... helper.
  • 16. MVC - View helper ● Helps you render HTML template that you use on many views. View helper: I can help you make things (php, js and html code) look nice.
  • 17. OOP - Model ● If you think you're using OOP because you have classes - you are wrong! ● "Happy" object should have just one responsibility. "Fat model" does not mean it has to have hundred lines of code. ● Object should be easy to test. You should be able to "mock" things it's using. ● Let object be dependent - inject into it the things it needs.
  • 18. MVC- Web Applications • When developing web applications, there are many traps regarding use of controllers : – Controller per Page : In this case you will end up creating too many controllers. However, controllers can handle more than one page. – Controller per Entity : This approach is too granular and may become even more challenging when we have more than one entity per view. Rails and Code Ignitor have this sort of controller per model approach. • It is advisable to write single test class per controller and prefer using MVC pattern. PHP OOP provides great functionality to avoid tight coupling.
  • 19. MVC - JavaScript ● All those rules applies to JavaScript and other languages. ● JavaScript code is also great when you use MVC! So you should/could have: MV(JS: MVC)C
  • 20. Zend Framework uses MVC - really? ● It's not a "true" MVC. ● MVC was designed for desktop apps. ● It has many "branches". @see MVP @see Model2 ("MVC for web apps")