Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I am trying to bridge a mental gap between the OOP principle of Layered Architecture[^] with the way that VS.NET starts a windows forms application. After designing my initial form I double click and get this code:
Public Class frmMain
    Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'code here'
    End Sub
    'other subs etc'
End Class
This does not give me a good way to set up all of my Layers since the only way to do so would mean putting "business layer" code into frmMain_Load() which is a User Interface Layer. In this blog: http://oopstruggles.blogspot.com/2008/10/oop-architecture.html[^] Tim gives an example of what I think this should look like with: class RealLife way down towards the bottom of his example.
 
I can think of a way to do this with a modMain module which contains a Public Sub Main() routine. This would be called by frmMain_Load(...)... in the main form when the application loads. But this all seems like I'm adding a band-aid to the way that VS.NET implements its solutions.
 
Am I using objects wrong if I need a facilitation sub like Tim is talking about? How should I set up my object facilitation code if that is the correct use of OOP Layers in VS.NET?
Posted 11-Feb-13 18:31pm
Comments
Sergey Alexandrovich Kryukov at 11-Feb-13 23:45pm
   
What is VS.NET Form application? :-) No, there is no such a beast.
What do you mean by administration of the application?!
What are "OOP layers"?
 
As I can see, you are asking about something which is nothing but a fruit of your own (or someone's) fantasy, not anything real...
—SA
Turbonate at 11-Feb-13 23:51pm
   
In Visual Studio 2012 if you click new > Project the very first option is "Windows Forms Application". This response makes me think you just answered without reading the post.
 
If you read into layers in OOP you'll know that there's a user layer, business layer and data layer which are supposed to be kept separate for best practices. It's all in the link that I posted in my first sentence.
 
It's not a fruit of my fantasy, thanks for the encouragement.
Sergey Alexandrovich Kryukov at 11-Feb-13 23:58pm
   
Maybe I'm just dumb; I read two times. :-)
I know what are layers, but why you call them "OOP layers"? Other things?
—SA
Turbonate at 12-Feb-13 0:04am
   
ok, I call them OOP Layers because they're listed in section 4.29 and 4.30 in the link titled: "Introduction to Object Oriented Programming Concepts (OOP) and More".
 
I'm trying to figure out how to separate my business layer from the forms layer (from an architectural standpoint) without relying on the user interface layer to start the application. I know what will work, but I'm more interested in the correct way to do this because procedural code "works", but it's a mess to work with.
 
I use the phrase administration because that's what I can think to call my application start-up sequence. I have to initialize all of my objects somehow, it just seems wrong to do that from a form.
Sergey Alexandrovich Kryukov at 12-Feb-13 0:09am
   
I see. This article is too shallow to consider it seriously. Read on major design patterns in, say, Wikipedia, and you will see how layers work. MVC, MVP, MVA and MVVM.
—SA
Turbonate at 12-Feb-13 0:15am
   
Thank you for the references. I'll do some more digging in that area.
Sergey Alexandrovich Kryukov at 12-Feb-13 0:25am
   
You see, this is a questions & answers forum, so the answers are not too big. To get effective help, it's the best if you have some well-defined goals. The good answers usually suggests some good techniques, help to resolve problem, point out some APIs, open-source libraries, and the like. If you read, study and get to such more specific area, we can help more effectively. (Just look at existing answers) Then come back.
 
How about that?
—SA
Sergey Alexandrovich Kryukov at 12-Feb-13 0:05am
   
OK. I see. You know, this is the issue: if you learn something choose good articles. I don't think any of the two articles you references are really useful. But even if they are useful to some extent... why anyone should consider then to answer you?
If you asked about something you want to achieve, it would make some sense...
 
There is nothing special about the handler of the Load event. This is pretty much "artificial" event; usually you can simply add your code to the constructor (to give you a hint). It is not directly related to layered architecture...
 
—SA
Turbonate at 12-Feb-13 0:13am
   
oh, the hint led me on. I can use the "handles mainform.load" event wherever I want to. I'm not tied to using the event in the form class.
 
right?
Sergey Alexandrovich Kryukov at 12-Feb-13 0:18am
   
You may or may not use it. I, for example, never use it, by some reasons. I define some Setup method, call it from the constructor at the very end, and create one more partial form declaration in separate file where I implement everything. It helps me to stay isolated from designer, which, by they way, should be used minimally, especially in big applications. I don't want to press on you with my methods, but it just to give you the idea...
—SA
Turbonate at 12-Feb-13 0:28am
   
I'm going to study up on this post tomorrow after I've had more sleep. Thank you for the answers, Cheers!
Sergey Alexandrovich Kryukov at 12-Feb-13 0:39am
   
Wasn't really an answer. You are welcome.
—SA
Turbonate at 12-Feb-13 9:44am
   
ha, well apparently it wasn't really a question until we started talking so we're even.
Sergey Alexandrovich Kryukov at 12-Feb-13 11:09am
   
In fact, a question mark saved your post for deletion. We are overwhelmed by non-questions, so big numbers of posts are being deleted in the very beginning, so I advise to show that the post is really a valid question clearly...
:-)
—SA
Turbonate at 12-Feb-13 13:05pm
   
I wouldn't be disapointed if this question is deleted since i know how confused I was when i wrote it. It is valuable to me but I don't know that it will help any other people. I will save a copy of the dialogue for myself.
Sergey Alexandrovich Kryukov at 12-Feb-13 13:16pm
   
OK. Just in case, always keep copies of your questions (or other important posts) in your records. Even if it is removed, you can post again, but of course take into account negative comments...
Cheers.
—SA
Turbonate at 12-Feb-13 9:45am
   
ok, so I figured out how to make most of this work with constructors. The last question I have is where the "start here" code can be besides the form.load event.
Sergey Alexandrovich Kryukov at 12-Feb-13 11:10am
   
Great.
—SA
Turbonate at 12-Feb-13 0:17am
   
and on the articles I posted, I ASSumed that posting what I've looked at will help frame the question. No sure that it helped in this case.
Sergey Alexandrovich Kryukov at 12-Feb-13 0:19am
   
What is really important is your goals. I just mentioned that I don't want to press with recommending of some of my methods too much. It could be worse if you accept some articles without critical thinking...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100