MVC vs MVP Architecture — What’s the Difference?

Listen to this Post

MVC (Model View Controller) and MVP (Model View Presenter) are design patterns that separate an application into distinct components. Both patterns aim to separate concerns, but they have some differences in their approach.

You Should Know:

1. User Interaction

Both patterns start when a user interacts with the application’s UI, which is managed by the View.

Practical Command Example (Linux):

 Monitor UI events in Linux desktop environments
xev | grep -A 2 --line-buffered '^KeyRelease' | sed -n '/keycode /s/^.keycode ([0-9]). (., (.)).$/\1 \2/p'

2. Event Handling

In MVC, the View forwards the event to the Controller. In MVP, the View forwards the event to the Presenter.

JavaScript Example:

// MVC Controller handling
document.getElementById('btn').addEventListener('click', function() {
controller.handleClick();
});

// MVP Presenter handling
document.getElementById('btn').addEventListener('click', function() {
presenter.onButtonClicked();
});

3. Business Logic

Both Controller and Presenter process events and apply business logic.

Python Example:

 MVC Controller business logic
class UserController:
def create_user(self, user_data):
if self.validate(user_data):
return self.model.save(user_data)
return False

MVP Presenter business logic
class UserPresenter:
def create_user(self, user_data):
if self.validate(user_data):
self.model.save(user_data)
self.view.show_success()

4. Model Update

Both patterns update models similarly.

Database Command Example:

-- SQL command that might be executed by Model
UPDATE users SET last_login = NOW() WHERE id = 123;

5. UI Updates (Key Difference)

  • MVC: View listens for Model changes
  • MVP: Presenter actively updates View

React Example (MVC-like):

// View observes model changes
function UserView({ user }) {
const [name, setName] = useState(user.name);
useEffect(() => {
const subscription = user.onChange(() => {
setName(user.name);
});
return () => subscription.unsubscribe();
}, [bash]);
return

<div>{name}</div>

;
}

Angular Example (MVP-like):

// Presenter updates view
@Component({
selector: 'app-user',
template: '

<div>{{name}}</div>

'
})
export class UserComponent {
name: string;
constructor(private userService: UserService) {
this.userService.getUser().subscribe(user => {
this.name = user.name;
});
}
}

Practical Implementation Commands

Linux System Monitoring (Relevant to Architecture Patterns):

 Monitor process communication (similar to component interaction)
sudo strace -p <PID> -e trace=network,ipc

View open file descriptors (like View observing Model)
lsof -p <PID>

Windows PowerShell Commands:

 Monitor UI events in Windows
Get-WinEvent -FilterHashtable @{LogName='Application'; ProviderName='Windows.UI'}

Docker Commands for Component Isolation:

 Run different components in separate containers
docker run -d --name model my-model-image
docker run -d --name view my-view-image --link model
docker run -d --name controller my-controller-image --link model --link view

What Undercode Say

The architectural patterns debate mirrors fundamental system design principles in IT infrastructure. Just as MVC/MVP separate concerns, Linux systems separate kernel space from user space. The `presenter` in MVP acts like a `systemd` service manager – actively coordinating between components rather than passive observation.

Key Linux commands that embody these patterns:

 MVC-like: inotifywait observes filesystem changes (View observing Model)
inotifywait -m /path/to/watch

MVP-like: actively pushing updates
rsync -avz source/ destination/

Windows equivalents demonstrate similar patterns:

 MVC-like: Event subscribers
Register-ObjectEvent -InputObject $object -EventName Changed -Action { ... }

MVP-like: Active updates
Set-ItemProperty -Path 'HKLM:\Software' -Name 'Value' -Value 'Data'

Database systems also implement these patterns:

-- MVC-like: Triggers (automatic updates)
CREATE TRIGGER update_view AFTER UPDATE ON model FOR EACH ROW EXECUTE FUNCTION update_view();

-- MVP-like: Stored procedures (active control)
CREATE PROCEDURE update_user(IN id INT, IN name VARCHAR) BEGIN ... END;

Expected Output:

When implementing MVC:

  1. User action → View → Controller → Model → View updates automatically

2. Components are more tightly coupled

3. Better for simpler applications

When implementing MVP:

  1. User action → View → Presenter → Model → Presenter → View

2. Components are more decoupled

3. Better for complex, testable applications

Reference URL for deeper understanding:

https://lnkd.in/g5uZ5u8R (Augment Code – AI assistant for real-world projects)

References:

Reported By: Nikkisiapno Mvc – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

Join Our Cyber World:

💬 Whatsapp | 💬 TelegramFeatured Image