473,729 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Where to Put DAL and Business Objects in WinForms App?

In Windows Forms MDI applications...

I'm wondering if it is standard practice to create DAL and business objects
as static classes. The only alternative (please enlighten me if I'm wrong
about this) is to instantiate the DAL and business objects in a Form class -
most likely the MDI parent - and then expose the business objects as public
members.

What is standard practice here? [assuming we're not using DCOM or Remoting
or Web services or any other such remote procedure calls].

Thanks!
Feb 7 '06 #1
3 2339
Smithers <A@B.COM> wrote:
I'm wondering if it is standard practice to create DAL and business objects
as static classes. The only alternative (please enlighten me if I'm wrong
about this) is to instantiate the DAL and business objects in a Form class -
most likely the MDI parent - and then expose the business objects as public
members.

What is standard practice here? [assuming we're not using DCOM or Remoting
or Web services or any other such remote procedure calls].


The disadvantage with using static classes is that you're then bound to
that implementation.

I prefer to use interfaces between layers, and use dependency injection
to give each layer the stateless objects from the layer below to use.
(If new objects need creating, they tend to be within layers, or could
be created with a factory pattern.)

Spring is a great way of doing dependency injection:
http://www.springframework.net

(I haven't used the .NET version, just the Java one, but it's great.
Really handy for unit testing, too.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 7 '06 #2
Total overkill in my humble opinion.
I think there are a good middle ground between simple static classes, and
creating a totally abstract, interface driven framework, dependant on a third
party library.

Don’t worry about stateless objects. If there are no remote objects (COM+,
WS, Remoting) there is absolutely no need to go create your classes so
they'll be stateless. just create normal instance based classes for your BL.
I tend to use factories to return objects from my DAL, but that’s just a
preference. You can go with normal instance based classes there as well.

One of my favorite quotes (from one of the TDD / Agile gurus) that I always
try to keep in mind when designing a new framework for an application goes
something like this. "Don't design something overly complex and unnecessary
just for the simple intellectual stimulation of it. Design for what you need
right now." You should keep in mind future extensibility, but don't just
through hoops to create the ultimate flexible framework. You'll end up with
way more than you ever need.
"Jon Skeet [C# MVP]" wrote:
Smithers <A@B.COM> wrote:
I'm wondering if it is standard practice to create DAL and business objects
as static classes. The only alternative (please enlighten me if I'm wrong
about this) is to instantiate the DAL and business objects in a Form class -
most likely the MDI parent - and then expose the business objects as public
members.

What is standard practice here? [assuming we're not using DCOM or Remoting
or Web services or any other such remote procedure calls].


The disadvantage with using static classes is that you're then bound to
that implementation.

I prefer to use interfaces between layers, and use dependency injection
to give each layer the stateless objects from the layer below to use.
(If new objects need creating, they tend to be within layers, or could
be created with a factory pattern.)

Spring is a great way of doing dependency injection:
http://www.springframework.net

(I haven't used the .NET version, just the Java one, but it's great.
Really handy for unit testing, too.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Feb 7 '06 #3
john conwell <jo*********@di scussions.micro soft.com> wrote:
Total overkill in my humble opinion.
It actually makes life a lot simpler, to be honest.
I think there are a good middle ground between simple static classes, and
creating a totally abstract, interface driven framework, dependant on a third
party library.
What's wrong with depending on a third-party library?
Don?t worry about stateless objects. If there are no remote objects (COM+,
WS, Remoting) there is absolutely no need to go create your classes so
they'll be stateless. just create normal instance based classes for your BL.
I tend to use factories to return objects from my DAL, but that?s just a
preference. You can go with normal instance based classes there as well.
And how do you unit test the classes which create DAL objects then? By
hard-coding your classes to create instances of each other, you're
adding dependencies which don't need to be there. Note that none of the
business classes themselves depend on Spring in the kind of setup I'm
talking about - Spring is just there to wire things up.
One of my favorite quotes (from one of the TDD / Agile gurus) that I always
try to keep in mind when designing a new framework for an application goes
something like this. "Don't design something overly complex and unnecessary
just for the simple intellectual stimulation of it. Design for what you need
right now." You should keep in mind future extensibility, but don't just
through hoops to create the ultimate flexible framework. You'll end up with
way more than you ever need.


Nope, I end up with exactly what I need - an application which is
really easy to unit test and configure. When all the collaborators are
set through interfaces, it means you can mock them very easily and
genuinely test just a unit instead of a whole bunch of classes at a
time.

The Spring framework developers are big Agile/TDD fans too, btw...
that's why it's a framework which scales down as well as up.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 7 '06 #4

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

Similar topics

4
2251
by: Simon Harvey | last post by:
Hello Chaps, Me and a collegue have been talking about where the best place to put business logic is. I think that the best place is where Microsoft suggest - in a seperate business logic layer. The alternative is to have all the logic in with the business entity objects, thus eliminating the business logic layer. The reason that I prefer the seperate layer is because I think its more
8
1934
by: ad | last post by:
I have studied buisness layer in http://beta.asp.net/QUICKSTART/util/srcview.aspx?path=~/aspnet/samples/data/GridViewObject.src It separate Author class to Author and AuthorComponent If I combine the two together into Author Class for convenience, like codes below: Is it ok to do that?
1
1403
by: John | last post by:
Hello everyone! I've read many articles about asp.net, business and data layers, and none of them seem to discourage the use of HttpContext specific variables in non-HttpContext specific layers; relying on the presence of the HttpSession or HttpRequest variables in the business layer for example. From what I can gather, doing this prevents these layers from being reused by different clients (winforms for example) since this context...
2
1593
by: Tim Smith | last post by:
Hi, With our architecture we are looking at the following client applications: - 20-40 GUI desktop power users - 40-100 ASP.NET light users - 5-10 heavy server side integration apps We would like to move all business logic into a single tier/layer. This tier would either run on the same machine as the ASP.NET or
3
1775
by: moondaddy | last post by:
I'm wanting to create a bindable list object made up of a list of business classes. I'm writing this in a vb.net 1.1 winforms app and am using a code example by Rocky Lhotka for reference material: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet02252003.asp which makes use of the IEditableObject interface. My situation is that my business class manages data for a table which has about 20 columns all...
2
1603
by: Mike | last post by:
Hello, I am working on a ASP.NET 1.1 project and would like to set up the web application to only have one unique Business Logic object that is created when the client connects. I would like to avoid re-instantiating the object every time a page is loaded (the connection to the DB are currently in a PageBase class). I basically would like to be able to re-use the web pages, call "generic" methods on my Business Logic, so that the web...
6
3799
by: Relaxin | last post by:
I'm coming from Borland C++ and am "somewhat" new to C#, but very seasoned in C++. I'm looking for a specific feature that Borland had that I can't seem to find in C#. In Borland that feature is a DataModule. This is a place where you place all of your Database and business logic. This logic can then be "bound" to your UI by use of Borland Datasource components.
1
1463
by: Mike | last post by:
Hi All, Is there a good book or paper on conceptualizing Winforms as objects? In object-oriented programming I don't find it diffiucult to see "student", "person", or "car" as objects, but I do have problems conceptualizing a "form" and controls on forms as objects and how they fit together. Is there anything specifically on dealing with forms while maintaining the OO model and design in C#? Thanks much,
2
2470
by: Andrus | last post by:
Winforms UI assembly has static FormManager.FormCreator method which creates forms taking entity as parameter. I need to pass this method to business objects in business assembly so that business methods can also create forms but does not have reference to UI assembly. I tried code below but got compile errows shown in comments. How to fix ? Andrus.
0
8917
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9281
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.