473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Towards Separating UI Code From All Other Code

Please note that this question is NOT about any particular pattern - but
about the general objective of separating out presentation logic from
everything else.

I'm trying to "get a grip" on some of the patterns (e.g., Model View
Presenter) or strategies for separating UI logic from the underlying
business rules and data.

As I understand it, the general intent of doing this is to reduce
dependencies amongst our classes in order to make the system more easily
extensible and maintainable. So in the case of Windows Forms applications,
we ultimately want a Form class that only deals with UI logic - while all
business logic is in some other independent class.

Specific Question: Where [do, should, can] we *instantiate* the non Form
classes in order to make them independent of the form on which its data is
being presented?

For example, in the Model View Presenter (or Controller) pattern, where
would we instantiate the Model and Presenter (or Controller) classes? The
View is obviously the Form class - but where do we actually *instantiate*
everything else in order to maintain the independence we're trying to
achieve by breaking out these classes to begin with? My thought is that if
they get instantiated in the Form module, then the classes are not really
independent - given that the form class must know what object type to
instantiate.

What am I missing?

Thanks for your time and consideration.

Feb 14 '06 #1
8 1789
I would take a different approach and say the main key is to separate
out the
application logic (Model) from the view and event handling code (View/
Controller). In MFC the Model is called the Document and everything else
goes
into what is called the View. In Unix the Model is called the ENGINE and
everything else goes into the INTERFACE. The simplest approach is to
consider
the Application as the Controller and this ApplicationController owns
the View
objects and Model object. Events are handled by the Controller that
updates and
queries the Model and then Updates the View.

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Feb 14 '06 #2
Maybe I am too dense to understand how your response addresses my specific
question which was specifically about *where do we instantiate* runtime
objects when we're trying to achieve independence.

When you state the following...
<< the Application as the ApplicationController owns the View objects and
Model object. Events are handled by the Controller >>
You are apparently stating that "the Application" is were everything gets
instantiated. What is "The Application" specifically in the case of a
Windows Forms application? Is it the Main form's (SDI) or MDI Parent form's
class module? Is it the runtime instance of the main form that we consider
to be "The Application"? ... and therefore in the main Form's class that we
instantiate all the other objects? I understand there isn't one way to do
this...I'm just asking for ONE way that I can understand!

Really trying to understand this...

Thanks again.



"Jeff Louie" <je********@yahoo.com> wrote in message
news:eM**************@TK2MSFTNGP12.phx.gbl...
I would take a different approach and say the main key is to separate
out the
application logic (Model) from the view and event handling code (View/
Controller). In MFC the Model is called the Document and everything else
goes
into what is called the View. In Unix the Model is called the ENGINE and
everything else goes into the INTERFACE. The simplest approach is to
consider
the Application as the Controller and this ApplicationController owns
the View
objects and Model object. Events are handled by the Controller that
updates and
queries the Model and then Updates the View.

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***

Feb 14 '06 #3
Jeff... if the the main application object owns the View and Model then
it is
using containment by ownership so that the View and Model objects are
created
or instantiated using the new key word in the main application object
source
code file eg. Form1.cs.

I have sample code here:

http://www.geocities.com/Jeff_Louie/OOP/oop3.htm

There is a link in there that lets you download the entire project.

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Feb 14 '06 #4

"Jeff S" <A@B.COM> wrote in message
news:e5**************@TK2MSFTNGP11.phx.gbl...
Please note that this question is NOT about any particular pattern - but
about the general objective of separating out presentation logic from
everything else.

I'm trying to "get a grip" on some of the patterns (e.g., Model View
Presenter) or strategies for separating UI logic from the underlying
business rules and data.

As I understand it, the general intent of doing this is to reduce
dependencies amongst our classes in order to make the system more easily
extensible and maintainable. So in the case of Windows Forms applications,
we ultimately want a Form class that only deals with UI logic - while all
business logic is in some other independent class.

Specific Question: Where [do, should, can] we *instantiate* the non Form
classes in order to make them independent of the form on which its data is
being presented?
In the class responsible for glueing the UI and the domain classes - the
controller. How is also an intersting question and the choice ranges from
direct instantiation to indirect instantiation (perhaps via dependency
injection using a container such as Spring.NET's, pico, Castle etc)
For example, in the Model View Presenter (or Controller) pattern, where
would we instantiate the Model and Presenter (or Controller) classes? The
View is obviously the Form class - but where do we actually *instantiate*
everything else in order to maintain the independence we're trying to
achieve by breaking out these classes to begin with? My thought is that if
they get instantiated in the Form module, then the classes are not really
independent - given that the form class must know what object type to
instantiate.

What am I missing?


Practical experience with simple but illustrative project(s). Have fun
playing with Spring.NET (or Castle) but, read Martin Fowler's piece on
dependency injection first I think.

Good luck.

Kunle

Feb 14 '06 #5
Thanks a bunch for the clarification. That helps, and it's as
straight-forward as I was suspecting it might be. I just read the Go4
Patterns book and some online stuff and NOWHERE did I see anyone talking
about specifically where these things get instantiated. I can understand the
concepts just fine and split the classes out - but when it's time to make
all hang together at runtime I got stuck. When it's presented independent of
actual code, then there is the illusion that these classes actually know
*noithing* about each other; but of course if that were really the case then
the app simply wouldn't work. The objects have to get instantiated
*somewhere* and it makes sense that it would be "at the application level" -
however that's done in the particular application type in question (Win
Forms, Web Forms, Console, etc.

Also thanks for the link. I'll be paying close attention.

-Jeff
"Jeff Louie" <je********@yahoo.com> wrote in message
news:e0*************@TK2MSFTNGP14.phx.gbl...
Jeff... if the the main application object owns the View and Model then
it is
using containment by ownership so that the View and Model objects are
created
or instantiated using the new key word in the main application object
source
code file eg. Form1.cs.

I have sample code here:

http://www.geocities.com/Jeff_Louie/OOP/oop3.htm

There is a link in there that lets you download the entire project.

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***

Feb 14 '06 #6
Jeff S wrote:

<snip>
Specific Question: Where [do, should, can] we *instantiate* the non Form
classes in order to make them independent of the form on which its data is
being presented?


This may well not apply to the situation you're in, but I've found that
an awful lot of the time, code can be made a lot simpler using a
pattern known as "dependency injection" (aka "inversion of control").
Here, instead of objects creating other objects directly, they are
usually provided their collaborators via properties (only knowing about
them as interfaces). In some cases, those collaborators may be
factories for other interfaces (eg you could have an IPersonQuery
interface which provides IPerson implementations when asked appropriate
questions).

You can then use a framework such as Spring.NET
(http://www.springframework.net) to "wire up" the application with
whatever implementation you require.

There's more information on this at the Spring.NET web site, amongst
other places. (I'm really still getting to grips with the whole thing
myself. I haven't needed to do much in the way of UI work, so it's hard
to know how much of it applies and how to the Model-View-Presenter
pattern.)

Jon

Feb 14 '06 #7

"Jeff S" <A@B.COM> wrote in message
news:e5**************@TK2MSFTNGP11.phx.gbl...
Please note that this question is NOT about any particular pattern - but
about the general objective of separating out presentation logic from
everything else.

I'm trying to "get a grip" on some of the patterns (e.g., Model View
Presenter) or strategies for separating UI logic from the underlying
business rules and data.

As I understand it, the general intent of doing this is to reduce
dependencies amongst our classes in order to make the system more easily
extensible and maintainable. So in the case of Windows Forms applications,
we ultimately want a Form class that only deals with UI logic - while all
business logic is in some other independent class.

Specific Question: Where [do, should, can] we *instantiate* the non Form
classes in order to make them independent of the form on which its data is
being presented?


By using reflection is entirely possible for there to be no code that knows
about anything other interfaces.

This is usually over idealistic and different approaches will be followed in
different circumstances. Putting the issue of interfaces aside:

1) The model should not depend on either the view or the controler since it
should be the least voltile part (in terms of code) and this is the main
motivation for the whole setup.
2) The controler must depend on both the model and the view since its whole
purpose is to mediate between them.
3) The view should not depend on the model because that would make the
controler redundant and it should not depend on the controler because that
would create a mutual dependency which would mean that there was no point in
separating view and controller.

These dependency "rules" imply that the only one of the three that could
directly instantiate the others would be the controler.
Feb 14 '06 #8
I've been looking at the MS Patterns and Practice groups "Composite UI
Application Block" (be prepared to spend a fair amount of time getting you
head around this!) - It is a complete framework that does exactly what you
want. It utilizes Observer, Factory, MVP / MVC, Builder, and other patterns
that are very common. So far I have been impressed and defeated, it's
powerful, but it's a major system to get used to. Also, prepare yourself
for a TON of classes, my god, there are so many classes. So far I have a
skeleton app with basic BOL/DAL layers in place and I'm over 20 classes.

It works though and it works well. Read more here:
http://www.gotdotnet.com/codegallery...a-f2eafbf2653c
and here:
http://msdn.microsoft.com/practices/...2/html/cab.asp

The samples are a little weak, they don't go deep enough for me, I still
have many questions. I would love to see this catch on though, It's real
powerful and if there were more people using it, I could have a better
chance of getting my 10+ questions answered ;0)

good luck.
"Jeff S" <A@B.COM> wrote in message
news:e5**************@TK2MSFTNGP11.phx.gbl...
Please note that this question is NOT about any particular pattern - but
about the general objective of separating out presentation logic from
everything else.

I'm trying to "get a grip" on some of the patterns (e.g., Model View
Presenter) or strategies for separating UI logic from the underlying
business rules and data.

As I understand it, the general intent of doing this is to reduce
dependencies amongst our classes in order to make the system more easily
extensible and maintainable. So in the case of Windows Forms applications,
we ultimately want a Form class that only deals with UI logic - while all
business logic is in some other independent class.

Specific Question: Where [do, should, can] we *instantiate* the non Form
classes in order to make them independent of the form on which its data is
being presented?

For example, in the Model View Presenter (or Controller) pattern, where
would we instantiate the Model and Presenter (or Controller) classes? The
View is obviously the Form class - but where do we actually *instantiate*
everything else in order to maintain the independence we're trying to
achieve by breaking out these classes to begin with? My thought is that if
they get instantiated in the Form module, then the classes are not really
independent - given that the form class must know what object type to
instantiate.

What am I missing?

Thanks for your time and consideration.

Feb 14 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
39
by: Joe Laughlin | last post by:
If I have a character array with "/some/file/directory/file_name", are there any functions / libraries that I could use to separate the directory ("some/file/directory") from the file name...
2
by: dis | last post by:
The following code introduces a 'generic function pointer' p. When calling the pointed-to function via this p, one has to typecast p towards a pointer to the type of the pointed-to function. My...
6
by: Chad Z. Hower aka Kudzu | last post by:
I want to do this. I want my programmers to do all the code. All of it - run at server and run at client. I then want a graphic artist to make the look and the layout of the pages. The...
3
by: mca | last post by:
Hi everyone, I'm new to asp.net and i have a question about separating the html code from the programming code. i have an unknown numbers of entries in my table. I want to make a hyperlink...
13
by: Michelle | last post by:
Hi all... I could use a little TLC here for understanding and not for solving a specific problem... sorry if I've got the wrong group, but I'm using VB so I figured this was the most appropriate...
0
by: Thag | last post by:
Hi! I am currently trying to get an overview about the possibility of separating graphical data from its animations. More specifically speaking, the graphical data is made up from 3D-CAD...
14
by: aaragon | last post by:
Hi everyone, I've been writing some code and so far I have all the code written in the .h files in order to avoid the linker errors. I'm using templates. I wanted to move the implementations to...
14
by: Gilles Ganault | last post by:
Hi One of the ways to raise performance for PHP apps is to separate static contents from dynamic contents, so that the former can be compiled once into cache. Can someone give me a simple...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.