|
If you need the dataLayer to be around for the entire class, your way is right.
Remember this object will be lying around for the duration of the existince of the BusinessLayer class - it will not be garbage collected.
If you create it within a method, it will be garbage collected if you are running out of space.
Personally, I would write this piece of code the way you have written it.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Good question (I've 5'd you) but personally, I think there are better solutions than both of the above. The business layer should be agnostic of the data layer as far as possible. The Data layer should have CRUD operations for the business objects, not the business layer calling the data layer. This is better separation of concerns IMO.
If you are actually "just" interested in persisting models (as opposed to doing this as an exercise in itself) it is worth giving the Entity Framework a look, or NHibernate. They map object model to relational models whilst having minimal/little impact on the purity of the object model itself.
|
|
|
|
|
The former approach is also used when it's desirable to keep the business object alive while at the same time releasing the data-layer object for garbage collection.
|
|
|
|
|
Nor of the two is fundamentally wrong. As other posters have pointed out it depends on the required life-time of the DataLayer object. I would however recommend to decouple the dependency between the layers via interfaces:
public interface IDataLayer {
void DoSomething(string firstName, string lastName);
}
public interface IDataLayerFactory {
IDataLayer Generate();
}
Then, your first and second alternatives become:
public class BusinessLayer {
private IDataLayerFactory dataLayerFactory;
protected BusinessLayer() {
dataLayerFactory = null;
}
public BusinesLayer(IDataLayerFactory pDataLayerFactory) {
dataLayerFactory = pDataLayerFactory;
}
public int Method1(string firstName, string lastName) {
return dataLayerFactor.Generate().DoSomething(firstName, lastName);
}
}
public class BusinessLayer {
private IDataLayer dataLayer;
protected BusinessLayer() {
dataLayer = null;
}
public BusinesLayer(IDataLayer pDataLayer) {
dataLayer = pDataLayer;
}
public int Method1(string firstName, string lastName) {
return dataLayer.DoSomething(firstName, lastName);
}
}
Of course there has to be an implementation:
class ASpecificDataLayer : IDataLayer {
public void DoSomething(string firstName, string lastName) {
}
};
class ASpecificDataLayerFactory : IDataLayerFactory {
public IDataLayer Generate() {
return new ASpecificDataLayer();
}
};
The fundamental difference is that your buiness layer does not depend on a specific implementation of a data layer, it only depends on the interface which can be implemented in various ways. This idiom is fundamental in OOD and is called dependency inversion. There is a lot of support for this pattern at framework level in form of so called dependency containers or service locators. Please google on the boldified termini for further information.
Cheers,
Paul
|
|
|
|
|
I already am aware the built in C# class can obtain the file version and product version 'strings' but I need to obtain the raw numeric values.
Is anyone aware of a public code base to do this?
I don't want to go off and make a DLL to be called by Interop or COM if I don't have to.
Thanks.
|
|
|
|
|
Hi , have a good day
Open a new C# Windows Application Project , Then :
- Menu -> Project -> "Your Project Properties" -> Settings
- Add new Setting , for example : "Setting1"
Execute the following code only once:
Properties.Settings.Default.Setting1 = "Hi , From setting1";
Properties.Settings.Default.Save();
Close your application
Then Run your Application again and Execute the following code :
MessageBox.Show(Properties.Settings.Default.Setting1);
The Question is :
Where is the value of setting1 saved ?
I know nothing , I know nothing ...
|
|
|
|
|
A file called "YourProjectName.exe.config"
It's just plain old XML.
|
|
|
|
|
Thank you so much ,
I was doing it the hard way , searching inside registry , system folder , windows folder
And it's was in front of me ( I am ashamed ) , Also I was confused with the other files in the debug folder
I know nothing , I know nothing ...
|
|
|
|
|
Just for your reference, I'm pretty sure a backup copy of those settings are embedded into the DLL (in case the config file gets deleted, I suppose). It doesn't change when you do the updates to the settings at runtime (only stores them when yo compile the DLL). At least I think that's how it works.
|
|
|
|
|
I am not sure if my subject line makes sense. But I want to create a simple user control that when consumed in aspx should have the following capability:
<uc1:addresscontrol id="AddressControl2" runat="server">
<addresslabel>Postal Address
<addresslabelcss>label
Where AddressLabel and AddressLabelCss are the properties of the control. This is just an example. But eventually I want a address control that will have labels and textboxes for address, city, state, zip. And want to give the user option to define the order himself. Something like gridview control. Example:
<uc1:addresscontrol runat="server">
..
<state>..
<city>..
Is this possible?
|
|
|
|
|
|
Hi Experts,
I want to make a website for selling my product. Please suggest should i go for website development in asp.net or php.
Since linux server does not support .net so i have to use windows server in case i select asp.net.
I do not have idea about which server is more secure (linux or windows)
Also which website provides better performance aspx or php
Please suggest.
|
|
|
|
|
Linux does support .NET via Mono.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
I would suggest you choose whichever technology you are more comfortable in.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
modified on Friday, October 15, 2010 11:11 AM
|
|
|
|
|
He should choose the technology you are most comfortable in?
|
|
|
|
|
yea! tongue-in-cheek....
|
|
|
|
|
Fixed. Thanks.
(remember its Friday evening here already )
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
I put this question not as a programmer.
I want someone to develop my website.
does .net is more advance than php.
search engine optimization is good for .net or php site
Which one you suggest
Also should i select static website or dynamic website by considering below points
performance,speed,page load time,search engine optimization etc
|
|
|
|
|
Noone here is going to write your site for you.
There is no one best web server/language combination that beats everything else. Performance is highly dependant on the person writing the site and they're knowledge, as well as the setup and administration of the web server(s), the database setup, design of the database, design of the app, ...
What gets used is far more dependant on your applications requirements, not the language that it's written in.
|
|
|
|
|
MKC002 wrote: Please suggest should i go for website development in asp.net or php.
Well, go with the one you are most comfortable with
MKC002 wrote: Since linux server does not support .net
have you heard of Mono
MKC002 wrote: I do not have idea about which server is more secure (linux or windows)
Both are as secure as you can properly secure them. Even the most secure platform can be compromised if not properly configured.
MKC002 wrote: Also which website provides better performance aspx or php
define Better. better in what? in performance, in maintainability, in coding, ....
|
|
|
|
|
performance. page load time in website etc
|
|
|
|
|
hi
how Communicated program with the lan to devices (for example plc)(a device that converts analog code to digital code)
|
|
|
|
|
|
hey friends..i display only one column in my datagrid and i want to make a search in it and i want to make that search by using stored procedure and i wrote a procedure for it..like below
ALTER procedure sp_SearchFirm
(
@aranan_firma nvarchar(50)
)
as
Begin
Select firma_adi From Firmalar Where firma_adi=@aranan_firma
End
and i have a DataAccessLayer class..in that class i wrote a method to work with that proc.like below
public DataSet SearchFirms(string aranan_firma)
{
try
{
cmd = new SqlCommand("sp_SearchFirm", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("@aranan_firma", System.Data.SqlDbType.NVarChar).Value = aranan_firma;
con.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
i try to return a DataSet to make it as source of datagrid i have in my main form..as u see i cant complete the method but the problem is that i didnt work with multilayer programming before and i cant find the right logic to make that search event and i dont know if i am on the right way or should i change my method i dont know.i will be pleased with any of your suggestion and idea..
|
|
|
|
|
How are you triggering the search, a button click, or perhaps textchange event? There is plenty of information availble on n-teir development, what have you researched so far? In a typical senerio the search event will call a business logic class, which will do any preprocessing or validation then pass the request to the data layer class which returns to the business class for any additional post processing of validation then back to the object making the call.
I know the language. I've read a book. - _Madmatt
|
|
|
|