Ads

Ads

Translate

Showing posts with label MVP. Show all posts
Showing posts with label MVP. Show all posts

Saturday, 23 November 2013

Metode MVC – Apa Pengaruhnya Bagi Para Programmer?


Masih ingat saya ketika masa-masa saya masih maniak koding dari awal ketika membuat sebuah aplikasi. Hampir seluruh kodingan yang saya buat hanya menggunakan komponen-komponen dasar yang ada pada bahasa pemrograman tersebut, sedikit sekali saya memakai komponen eksternal atau tool pembantu. Pokoknya ngoding poll dari awal dan comot kodingan sana-sini dari internet dan ujung-ujungnya jadilah program gado-gado tanpa struktur yang jelas, saya sendiri pusing kalo disuruh ngeliat kodingan saya jaman dulu, waduh bikin mata serasa mau copot :nohope:
Teman sesama peneliti saya, Putra Setia Utama, sering menyarankan saya untuk menggunakan komponen yang sudah ada seperti YUI untuk interface web dan beberapa lainnya yang saya gak apal hehe soalnya dulu biasanya saya acuhkan hal seperti itu. Namun sejak tahun lalu saya mulai sadar betapa bodohnya saya, terus menerus mengoding dari awal hal yang sama secara berulang-ulang.
Tahun lalu saya “terpaksa” menggunakan framework untuk Java berbasis Model View Controller (MVC), yaitu Hibernate dan Spring, dikarenakan oleh tuntutan tempat dimana saya sedang praktek kerja lapangan (PKL) waktu itu. Bagi saya yang terbiasa ngoding dari awal, belajar menggunakan Hibernate dan Spring itu seperti neraka, pusing sekali saya waktu itu. Hibernate dengan konsep ORM-nya yang berbeda jauh dengan query SQL manual dalam pemrosesan data dan Spring dengan konsep MVC-nya yang ngebuat saya serasa seperti alien di dunia pemrograman.
1 bulan saya berkutat dengan Hibernate dan Spring akhirnya saya mendapatkan pencerahan hehe :siul: . Metode pemrograman yang dulu saya bisa membutuhkan 3 bulan untuk mengerjakan web berjenis databank, sekarang bisa saya kerjakan dalam waktu kurang dari 1 bulan. Dan jika ada revisi, saya tidak repot-repot lagi harus mengecek semua halaman web yang saya buat, karena dengan menggunakan framework hampir semuanya sudah terstruktur dengan rapih sehingga memudahkan saya untuk memodifikasi web tersebut.
Penggunaan framework MVC sangat membantu saya dan tentunya programmer lainnya, baik itu programmer web, desktop, atau mobile. Dengan menggunakan framework biasanya kita akan dibantu hal-hal seperti query database, manajemen source code, validasi data, keamanan, dan lain-lain. Setelah saya melihat berbagai macam hal yang dapat mempengaruhi kinerja programmer dengan menggunakan framework MVC saya langsung beralih menjadi programmer berbasis framework hehe, gak mau lagi saya disuruh ngoding secara manual yang ampe ratusan bahkan ribuan kodingan yang isinya kebanyakan validasti data, query, keamanan, dan lain-lain yang bersifat repetitif di setiap proyek aplikasi, tinggal programming santai saja saya hehe :linux2:
Saya menjadi sadar bahwa selama ini yang saya lakukan adalah memeras diri sendiri dan “reinvent the wheel”, artinya saya bersusah payah untuk melakukan hal yang sudah ada. Berikut saya berikan poin-poin penting dari keuntungan menggunakan framework MVC menurut saya:
  1. Programmer akan sangat terbantu dalam membuat kodingan-kodingan yang bersifat repetitif
  2. Source code secara otomatis akan mengikuti struktur file yang ada di framework tersebut sehingga memudahkan manajemen source code
  3. Kebanyakan perusahaan sekarang membutuhkan programmer yang bisa menggunakan framework MVC, artinya peluang kerja semakin besar dibanding yang ngoding dari awal
  4. Biasanya gaji programmer yang menggunakan framework MVC lebih mahal dibanding yang ngoding dari awal
Walaupun begitu, mengoding dari awal tetap diperlukan ketika kita belajar pemrgoraman. Soalnya dengan mengoding dari awal itulah kita bisa mengeri konsep dan basis pemrograman, kalau langsung menggunakan framework MVC kemungkinan besar anda akan bingung karena anda akan dijejali dengan berbagai macam konsep-konsep Object Oriented Programming (OOP) seperti inheritance, override, abstraction, dan lain-lain. Setelah kita mengerti konsep dan basis pemrograman barulah kita beralih ke penggunaan framework MVC.
Terakhir, walaupun penggunaan framework MVC memberikan kita banyak keuntungan tapi jika kita menggunakannya secara asal maka akan berdampak terbalik buat kita seperti program menjadi lebih berat untuk dijalankan dan lain-lain. Tetap kita harus teliti dalam mengoding dan memahami MVC secara mendalam agar aplikasi yang kita buat berjalan dengan nyaman. Saya pribadi memang agak susah untuk memahami konsep framework MVC pertama kalinya, tapi setelah anda terbiasa, bikin program udah tinggal libas aja hehe.
Selamat belajar dan kampanyekan programming sehat menggunakan framework MVC hehe.

* Untuk tambahan, berikut adalah framework MVC yang sudah pernah saya gunakan, siapa tau bermanfaat:
  1. Java: Hibernate (Model) + Spring (View, Controller)
  2. PHP: Doctrine (Model) + CodeIgniter (View, Controller), kebetulan untuk yang ini ada tutorial di jurnal ini di link ini

Disadur dari : http://www.teknojurnal.com/2010/02/24/framework-mvc-apa-pengaruhnya-bagi-para-programmer/

Tuesday, 29 October 2013

MVC or MVP Pattern – Whats the difference?


Over the years I have mentored many developers on using design patterns and best practices. One question that keeps coming up over and over again is: What are the differences between the Model View Controller (MVC) and Model View Presenter (MVP) patterns? Surprisingly the answer is more complex than what you would suspect. Part of reasons I think many developers shy away from using either pattern is the confusion over the differences.
Before we dig into the differences let’s examine how the patterns work and the key benefits to using either one. Both (MVC & MVP) patterns have been use for several years and address a key OO principal namely separation of concerns between the UI and the business layers. There are a number of frameworks is use today that based on these patterns including: JAVA Struts, ROR, Microsoft Smart Client Software Factory (CAB), Microsoft Web Client Software Factory, and the recently announced ASP.Net MVC framework.
Model View Controller (MVC) Pattern

The MVC pattern is a UI presentation pattern that focuses on separating the UI (View) from its business layer (Model). The pattern separates responsibilities across three components: the view is responsible for rending UI elements, the controller is responsible for responding to UI actions, and the model is responsible for business behaviors and state management. In most implementation all three components can directly interact with each other and in some implementations the controller is responsible for determining which view to display (Front Controller Pattern),
Model View Presenter (MVP) Pattern
 
The MVP pattern is a UI presentation pattern based on the concepts of the MVC pattern. The pattern separates responsibilities across four components: the view is responsible for rending UI elements, the view interface is used to loosely couple the presenter from its view, the presenter is responsible for interacting between the view/model, and the model is responsible for business behaviors and state management. In some implementations the presenter interacts with a service (controller) layer to retrieve/persist the model. The view interface and service layer are commonly used to make writing unit tests for the presenter and the model easier.
Key Benefits
Before using any pattern a developers needs to consider the pros and cons of using it. There are a number of key benefits to using either the MVC or MVP pattern (See list below). But, there also a few draw backs to consider. The biggest drawbacks are additional complexity and learning curve. While the patterns may not be appropriate for simple solutions; advance solutions can greatly benefit from using the pattern. I’m my experience a have seen a few solutions eliminate a large amount of complexity but being re-factored to use either pattern.

·         Loose coupling – The presenter/controller are an intermediary between the UI code and the model. This allows the view and the model to evolve independently of each other.
·         Clear separation of concerns/responsibility
o    UI (Form or Page) – Responsible for rending UI elements
o    Presenter/controller – Responsible for reacting to UI events and interacts with the model
o    Model – Responsible for business behaviors and state management
·         Test Driven – By isolating each major component (UI, Presenter/controller, and model) it is easier to write unit tests. This is especially true when using the MVP pattern which only interacts with the view using an interface.
·         Code Reuse – By using a separation of concerns/responsible design approach you will increase code reuse. This is especially true when using a full blown domain model and keeping all the business/state management logic where it belongs.
·         Hide Data Access – Using these patterns forces you to put the data access code where it belongs in a data access layer. There a number of other patterns that typical works with the MVP/MVC pattern for data access. Two of the most common ones are repository and unit of work. (See Martin Fowler – Patterns of Enterprise Application Architecture for more details)
·         Flexibility/Adaptable – By isolating most of your code into the presenter/controller and model components your code base is more adaptable to change. For example consider how much UI and data access technologies have changed over the years and the number of choices we have available today. A properly design solution using MVC or MVP can support multi UI and data access technologies at the same time.
Key Differences
So what really are the differences between the MVC and MVP pattern. Actually there are not a whole lot of differences between them. Both patterns focus on separating responsibility across multi components and promote loosely coupling the UI (View) from the business layer (Model).  The major differences are how the pattern is implemented and in some advanced scenarios you need both presenters and controllers.

Here are the key differences between the patterns:

·         MVP Pattern
o    View is more loosely coupled to the model. The presenter is responsible for binding the model to the view.
o    Easier to unit test because interaction with the view is through an interface
o    Usually view to presenter map one to one. Complex views may have multi presenters.

·         MVC Pattern
o    Controller are based on behaviors and can be shared across views
o    Can be responsible for determining which view to display (Front Controller Pattern)

Hopefully you found this post interesting and it helped clarify the differences between the MVC and MVP pattern. If not, do not be discouraged patterns are powerful tools that can be hard to use sometimes. One thing to remember is that a pattern is a blue print and not an out of the box solutions. Developers should use them as a guide and modify the implementation according to their problem domain.

Reference : http://www.infragistics.com/community/blogs/todd_snyder/archive/2007/10/17/mvc-or-mvp-pattern-whats-the-difference.aspx

Best Post This Year

Install Fortesreport community Delphi 7 dan RX Berlin

Download  Pertama2 kita harus punya file installernya terlebih dahulu, download  https://github.com/fortesinformatica/fortesrepo...

Total Pageviews

© 2014 Fajar Priyadi. WP themonic converted by Bloggertheme9. Published By Gooyaabi Templates | Powered By Blogger
TOP