473,406 Members | 2,705 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,406 software developers and data experts.

Model View Controller?

I have the following problem:

I have written a class which works on image data.
To be precise.... the class applies smoothening on the image with filters.

I want to visualize this proccess.
To do this i am going to write a second class, which is responsible
for displaying the smoothening in progress.

Because i only want this visualisation for control purpose, i dont want
any visualisation methods in the first class. This would deminish it's
efficency. The Model View Controller Pattern, relies heavily on
Messaging between the classes, so the first class would have
to inform the second, and as i said, i dont want any inform methods in
the first class.

My Idea is to create two threads, the first filtering the images, the second
accessing the resources(image) of the first class and displaying them from
time to time.

Any better suggestion?

THX



Apr 5 '06 #1
6 2537
Radium wrote:
I have the following problem:

I have written a class which works on image data.
To be precise.... [...]

My Idea is to create two threads, [..]

Any better suggestion?


Arguable but possibly better to post to 'comp.object', since C++ does
not have any built-in threading support, nor your problem is of the
language kind. Also consider 'comp.software.patterns'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 5 '06 #2
Radium wrote:
I have written a class which works on image data.
To be precise.... the class applies smoothening on the image with filters.

I want to visualize this proccess.
To do this i am going to write a second class, which is responsible
for displaying the smoothening in progress.

Because i only want this visualisation for control purpose, i dont want
any visualisation methods in the first class. This would deminish it's
efficency. The Model View Controller Pattern, relies heavily on
Messaging between the classes, so the first class would have
to inform the second, and as i said, i dont want any inform methods in
the first class.
The simplest form of MVC is just method calls. No threads, or Observer
Pattern.
My Idea is to create two threads, the first filtering the images, the
second
accessing the resources(image) of the first class and displaying them from
time to time.

Any better suggestion?


Ideally, the filter program's work loop should be interruptible, so an outer
loop could call it over and over again, incrementing an index which is a
member variable, each time.

Then your GUI layer could use a window timer set to 0 duration. Each timer
event calls a handler that calls the filter program a number of times -
maybe until 100 milliseconds elapse - and then collects data and triggers a
paint event. The next window handler won't run until the paint is done.

Whenever a program might use threads, I personally work hard to avoid them,
and this tends to improve the code in ways that make threads easier to
install after you need them. For example, a work loop inside another thread
could intermittently call PostMessage() (on Win32) to send a WM_USER message
to a window, and that would paint.

Such a system would use threads in almost the same configuration as my
thread-free version.

I X-posted to news:comp.object for advice from beyond C++.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 5 '06 #3
On Wed, 05 Apr 2006 22:10:57 GMT, Phlip wrote:
Ideally, the filter program's work loop should be interruptible, so an outer
loop could call it over and over again, incrementing an index which is a
member variable, each time.
This would be a very fragile design, though. Then, if there are some time
constraints, it becomes quite difficult to handle them. Yes, it is simpler
as long as the system is small, but its complexity grows much faster than
one of natively-concurrent design.
Then your GUI layer could use a window timer set to 0 duration. Each timer
event calls a handler that calls the filter program a number of times -
maybe until 100 milliseconds elapse - and then collects data and triggers a
paint event. The next window handler won't run until the paint is done.
I would prefer a threaded design to timers. The reason is that this
provides a good isolation of things which have to be decoupled: like worker
vs. GUI, and also because it allows finer time granularity. Usually I am
using three threads:

1. Worker
2. GUI messages loop (to handle user input)
3. GUI visualization

I don't recommend to use WM_TIMER in order to merge 2 and 3. In my
experience it is cleaner to run 3 periodically, usually at 20-50ms rate for
highly dynamic data. Especially when the requirement is that 2 should never
be blocked. The design of many windows applications suffers this problem.
Another argument, is that it is a good soft-real time approach. Usually 3
would take much resources. Running it at known rate warranties that
whatever happens it wouldn't take more than that. If system gets busy one
could no the fly brake 3 by decreasing its rate. This is how oscilloscopes
and other things alike are implemented in our commercial HMI.
Whenever a program might use threads, I personally work hard to avoid them,
and this tends to improve the code in ways that make threads easier to
install after you need them. For example, a work loop inside another thread
could intermittently call PostMessage() (on Win32) to send a WM_USER message
to a window, and that would paint.


Yes, it is possible, but it is fragile and also has a poor performance.
Sending messages involves queuing (=unpredictable time) + context switches
(=wasting resources.) Protected objects (implemented on the basis of
critical sections) are much more faster and for all cleaner.

Having said that, I'd like to note that I agree with the advice to develop
components in a thread-free way. I.e. that each object is basically
passive, but is activated from outside by some pace-maker thread. The
difficult decision is though, whether a particular object need to be
thread-safe.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Apr 6 '06 #4
Responding to Kazakov...
Ideally, the filter program's work loop should be interruptible, so an outer
loop could call it over and over again, incrementing an index which is a
member variable, each time.

This would be a very fragile design, though. Then, if there are some time
constraints, it becomes quite difficult to handle them. Yes, it is simpler
as long as the system is small, but its complexity grows much faster than
one of natively-concurrent design.


Right. But I think that is inherent in using MVC in the first place.
MVC presupposes a layered model structure where the dominant activity is
converting back and forth between the RDB and UI paradigms. IOW,
CRUD/USER processing. In such a context fragility is not a concern
because the view conversions are so rigorously defined. But as soon as
one starts getting into other operational concerns, like R-T
constraints, one is in a different ball game where there is no inherent
structure to prevent foot-shooting. So one needs an entirely different
model tailored to the context (in this case, asynchronous processing),
such as you suggest.
Whenever a program might use threads, I personally work hard to avoid them,
and this tends to improve the code in ways that make threads easier to
install after you need them. For example, a work loop inside another thread
could intermittently call PostMessage() (on Win32) to send a WM_USER message
to a window, and that would paint.

Yes, it is possible, but it is fragile and also has a poor performance.
Sending messages involves queuing (=unpredictable time) + context switches
(=wasting resources.) Protected objects (implemented on the basis of
critical sections) are much more faster and for all cleaner.

Having said that, I'd like to note that I agree with the advice to develop
components in a thread-free way. I.e. that each object is basically
passive, but is activated from outside by some pace-maker thread. The
difficult decision is though, whether a particular object need to be
thread-safe.


Ironically, one problem with threads is that they usually have poor
performance. Typically one is actually using the OS thread
infrastructure, which has to deal with time slicing at the instruction
level. That entails a whole lot of overhead for context switches. So I
agree with you and Phlip that one wants to look for an alternative
whenever possible.

In fact, most applications' time constraints aren't so stringent that
one needs slicing at the instruction level. So one can use slicing at
the method level where one gets context switches for free. One way to
do that is through interacting object state machines where there are
multiple event queue managers that effectively act as threads (i.e.,
only one queue pops at a time and semaphores or whatever determine who
pops next).

It is no panacea (e.g., an entire object state machine must be assigned
to a single event queue), but this sort of Poor Man's Threading is
surprisingly useful in well-formed OO applications where objects are
cohesive, responsibilities are logically indivisible, and collaborations
are peer-to-peer. It is also pretty robust because the original
asynchronous communication solution one needed for the state machine
interactions goes a long way to ensure proper sequencing and the few
situations where the developer needs to intervene explicitly are usually
pretty obvious.
*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hs*@pathfindermda.com
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
(888)OOA-PATH

Apr 6 '06 #5
On Thu, 06 Apr 2006 15:41:55 GMT, H. S. Lahman wrote:
Responding to Kazakov...

In fact, most applications' time constraints aren't so stringent that
one needs slicing at the instruction level. So one can use slicing at
the method level where one gets context switches for free. One way to
do that is through interacting object state machines where there are
multiple event queue managers that effectively act as threads (i.e.,
only one queue pops at a time and semaphores or whatever determine who
pops next).


Yep. Interestingly, but what you describe is actually how protected objects
work. On a single processor machine the implementation of would most likely
be one mutex for all objects. Each time a protected action ends (=the state
machine performs a transition) the barriers of the protected object entries
are reevaluated letting some threads to continue. The advantage of this
model is that if the current thread can continue, it will. This minimizes
context switches. The mutex is only used to protect the actions = state
machine transitions. The rest happens fully concurrently. So the barriers
play the role of semaphores. It is a very lightweight model. When
implemented by the language within one OS thread it should beat all other
mechanisms. Unfortunately one cannot use this at full, because when some
synchronous I/O or GUI API of the OS used they, of course, would block
everything in that is single thread. So except for rare stand-alone cases,
one should still use these clumsy OS threads. Still protected objects are
more efficient than mutexes, very OO-ish and well fit for OO decomposition.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Apr 6 '06 #6
Responding to Kazakov...
In fact, most applications' time constraints aren't so stringent that
one needs slicing at the instruction level. So one can use slicing at
the method level where one gets context switches for free. One way to
do that is through interacting object state machines where there are
multiple event queue managers that effectively act as threads (i.e.,
only one queue pops at a time and semaphores or whatever determine who
pops next).

Yep. Interestingly, but what you describe is actually how protected objects
work.


I know. B-) It is one of the reasons translation insists on describing
all object behavior with object state machines. Once one has that
infrastructure and rigor, the code generator can automatically identify
objects that need to be protected based on synchronous knowledge access
and then provide the appropriate blocking management. [Alas, the
current state of the art still requires the developer to provide some
help indirectly through an MDA marking model. But the grunt work can be
automated.]
*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hs*@pathfindermda.com
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
(888)OOA-PATH

Apr 8 '06 #7

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

Similar topics

2
by: Tony Marston | last post by:
For those who you thought my method of implementing OO principles in PHP was totally wrong - see http://www.tonymarston.co.uk/php-mysql/good-bad-oop.html for details, you can now read...
13
by: Droolboy | last post by:
I'm trying to build a fairly small (max. 10 different pages) site using php, and it's becoming obvious that I need some kind of model view separation. Having done a few searches, I've come...
7
by: pysim | last post by:
Hi, I have a couple of general requests for pointers to python examples and design advice. I'm looking for examples of MVC-based GUI controls done in python (model-view-controller). Also,...
0
by: Fritz Bosch | last post by:
We are in the process of refactoring our GUI-based test application for radio equipment and are rewriting a significant part in Python. The new architecture will substantially be based on the...
7
by: hugo.elias | last post by:
Hi all, I hope nobody minds me posting this question to this group, but I couldn't find any group closer to the Subject. Can anyone clear up where you draw the lines when dividing up an...
6
by: Robert W. | last post by:
I'm building my first major C# program and am try to use best practices everywhere. So I've implemented the "Document/View Model" whereby: - There's a Windows Form, which we'll call "formView" -...
6
by: cmay | last post by:
I have been looking over the UIPAB and how you can use it in ASP.Net. It seems like, at least from the article that I read, that there really isn't a Model in this architecture, even though...
4
by: Griff | last post by:
Two questions really, the first one "conceptual" and the other more involved with design: 1 - There are two schools of thought where I work on the role of the "controller" task. The first is...
12
by: Doug | last post by:
Hi, I learned a little about the model view presenter pattern at a conference this last week and am experimenting with it. It's working pretty well but I have a question. I am trying to use...
6
by: Bill44077 | last post by:
Hi, I am new to the MVP pattern and one of the main reasons that we are going this route is because we are doing Scrum with 30 day sprints - so we have a continually morphing design. We are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.