|
|
Hi All,
I am developing a library component which requires some global settings. Personally I don’t like to maintain an xml configuration file for this.
An idea strikes for me that to write an abstract class with an abstract method which can override and set global setting by the implementers of this library.
The abstract class will look like something like this.
public abstract class LibSetting
{
public int MaxCount { get; set; }
public abstract void SetCount();
}
The end users will implement this abstract class in their application is as follows.
public class MySetting : LibSetting
{
public override void SetCount()
{
MaxCount = 100;
}
}
To get the end user setting from my library, I am using following code.
public int ShowCount()
{
Assembly asm = Assembly.GetCallingAssembly();
IEnumerable<Type> types = asm.GetTypes().Where(t => t.IsClass && t.BaseType == typeof(LibSetting));
LibSetting setting =(LibSetting) asm.CreateInstance(types.First().FullName);
setting.SetCount();
return setting.MaxCount;
}
This will work perfectly. My doubt is that, is it feasible in architecture level of view? I think the performance of read an xml file and loading a class using reflection would be same ( I didn’t test it). So is this a good practice? Kindly advice me on this.
Thanks and Regards,
Kannan
|
|
|
|
|
Hi Kannan,
Your inheritance approach seems fine.
I have the following things that you can ponder about:
1) Isn't the user's call to a setter a little backwards?
Another approach is just to require a getter from the user's concrete class e.g.
public abstract class LibSetting
{
public abstract int MaxCount { get; }
}
2) Furthermore, you could supply the user with good default settings e.g.
public abstract class LibSetting
{
public virtual int MaxCount
{
get { return 100; }
}
}
Hope it makes sense...
Regards, Keld Ølykke
|
|
|
|
|
Hello,
I have been designing a cross-platform GUI application using JUCE framework and need some help in designing it.
The GUI will be used for configuring the hardware/device.
I did layering for the application as below.
- Presentation Layer
- Controller Layer
- Model Layer
- Communcation Layer
I’ll explain each of them as below.
Model Layer: It contains the actual data that is displayed in the UI and stored in the hardware/device.
For e.g Device Information (ID, Name, version number)
Presentation Layer: It displays the information present in the Model/Hardware or the information after being manipulated in the Model. Mainly, it acts a View.
Controller Layer: It controls the requests coming from presentation layer and hardware/model layer.
Communication Layer: It communicates with the actual hardware through some protocol and send/receive from/to controller.
So, the basic flow from UI to device will be
Presentation -> Controller -> Communication -> H/W -> Receive message from H/W -> Communication -> controller -> Model and Presentation
And reverse would be
Receive message from H/W -> communication -> controller -> model and presentation.
Here are my questions w.r.t design.
- Model will have entities such as Employee, Department which will be used inside the controller. Shall I create a EmployeeController and departmentController OR should I have a single controller class only
- If I wanted to show information of an emplyee in a department in UI, should I create corresponding views in the UI such as employeeView and departmentView.
- What patterns we can apply for different layers, especially for GUI
- Where should I write the observer pattern in order to update the UI when there is a change in the value of the Model.
- Appreciate if someone can provide me an example for Loosly coupled GUI application in C++ and that interacts with the hardware.
Please let me know for any clarification.
Thanks in advance for your time and effort.
Praveen Raghuvanshi
Software Developer
|
|
|
|
|
Looking for a third party chat service where site visitors can live chat with reps and during off hours have an automated response for basic visitor questions.
|
|
|
|
|
Your question ain't really related to 'Desgin and Architecture'. I think you will be better of, asking this question in one of the forums related to the technology you are using, eg. asp.net.
|
|
|
|
|
Try Google, there are lots of ready made packages around.
I must get a clever new signature for 2011.
|
|
|
|
|
I've developed on an application for quiet long now, and it consist of 2 sub systems, 1 for Marketing and 1 for Management. They have an seperated DB each. Now I have an UI that have to pick information in both databases, and I wondered if my controller pattern was correct, since I somehow got the idea that a UI that have connection to both Controller Facades, must be somehow incorrect?
My original setup was like this:
[UI]
------Controllers------
[Business Logic]
------Datacontext------
MarketingDB | ManagementDB
I don't know if it give you any sense? The controller on the drawing consist of the 2 controllers described above. Would it be right to make an on-top controller and call that one FrontController, so ALL UI's are connection to the FrontController no matter if they are Marketing UIs or Management UIs? Imo that gives you the ultimate of low coupling between UI and business layer, and lowest coupling between the Controllers and the UI layer, but I don't know if this is 'correct' or wrong? What is your oppinion???
I have two drawings to show the concept I wanted to do:
http://img192.imageshack.us/i/controllerdomaincontrol.jpg/[^]
ONLY FrontController:
http://img62.imageshack.us/i/controllerfrontcontroll.jpg/[^]
Which one would you prefer as correct architecture? And why?
|
|
|
|
|
I prefer front controller because by adding a layer you can abstract your sub controllers and stimulating immagination
Piccadilly Yum Yum
|
|
|
|
|
But won't it just be another class class with duplicated code, containing all the method's from sub-controllers? Or are there any smart way to do it?
|
|
|
|
|
It depends on what is the job of controllers, your architecture is not the only possible, i post a fragment from wikipedia about architectures :
Architecture description languages
Architecture description languages (ADLs) are used to describe a Software Architecture. Several different ADLs have been developed by different organizations, including AADL (SAE standard), Wright (developed by Carnegie Mellon), Acme (developed by Carnegie Mellon), xADL (developed by UCI), Darwin (developed by Imperial College London), DAOP-ADL (developed by University of Málaga), and ByADL (University of L'Aquila, Italy). Common elements of an ADL are component, connector and configuration.
Piccadilly Yum Yum
|
|
|
|
|
I'm looking for a good way to send notifications to our group when the results of a stored procedure cross a certain threshold. An example would be we have a table that acts as a queue for processing and when the number of records in a processing status is greater than say 10 I would like to receive an email. Is there a better way of doing this other than running a windows service thats polling the database? Thanks in advance.
Greg
modified on Monday, March 7, 2011 5:33 PM
|
|
|
|
|
gbovee wrote: Is there a better way of doing this other than running a windows service thats polling the database?
Since you only get a value when you execute it, there'd be no alternative to polling. You'd have to execute the sproc to see if the value changed.
What does the sproc do? Perhaps the logic can be moved elsewhere?
I are Troll
|
|
|
|
|
Hi,
I know, a well designed architecture should not allow a presentation layer to talk to Data Access Layer. Rather Presentation layer should talk to Business Logic Layer and Business Logic Layer should talk to Data access layer.
In my Data access layer, I have method
public static employee GetEmployee(string emailAddress)
{
using (EmployeeDBDataContext myDbContext = new EmployeeDBDataContext())
{
employee empRecord = myDbContext.employees.Where(aRec => aRec.emailAddress == emailAddress).ToArray().SingleOrDefault();
return empRecord;
}
}
My Presentation Layer's job is to display the properties of the employee object directly to the UI, where I do not even need to write any code for that.
Ok, now, should I create a thin Business Logic layer just to mediate the call of Presentation layer ? Then, it may look very messy as I will have to create a set of methods in BLL duplicating the method signature from DAL. Would you please tell me what could be a better practice ?
modified on Monday, February 28, 2011 5:12 AM
|
|
|
|
|
My first thought looking at this example is that you are awfully trusting. By that I mean that you are trusting input that has not been validated. What happens if email is an empty string, or not a valid email format? This is the type of thing that a well constructed business layer helps to cope with.
|
|
|
|
|
Thanks for your kind reply.
I see. So, I got something to do (validating inputs) for BLL. But, I do the validation in Presentation Layer as the validation is highly related to the UI. For example, if the input is coming from a Slider, then, my validation code will use the Slider's property. If my email address is coming from a text box, then, my Validation code will use the text box property to check. Yes, if I use a Regex to validate an email address, I encapsulate that Regex code in a method in my BLL and call that method from my Validation logic in Presentation layer so that the Presentation layer does not look thick.
Other than validation, is there anything that I may need to know so that I can involve BLL between DAL and Presentation Layer ?
|
|
|
|
|
As the name suggests, the BLL is intended for business logic. If you don't have business logic there is nothing to say you need to have this layer in place. I will say, though, that separating the validation, etc, from the presentation should help to make your app more testable because you can use a tool like nunit to test it, rather than relying on randomly pushing buttons.
|
|
|
|
|
Thank you very much. Now, I got the direction.
|
|
|
|
|
Nadia Monalisa wrote: I know, a well designed architecture should not allow a presentation layer to talk to Data Access Layer. Rather Presentation layer should talk to Business Logic Layer and Business Logic Layer should talk to Data access layer.
According to whom? I don't like these kind of generalizations, as these rules-of-thumb are often used to avoid critical thinking. This specific rule-of-thumb applies to datacentric-applications, not to some game like World of Warcraft. Now to refine your statement; it might be benificial to introduce an abstraction-layer, but it shouldn't be an excercise where you merely duplicate the interface of the datalayer, since that would only eat up your time without providing much benefits.
I got a small app that stores passwords - no datalayer. But the issue-manager does have one, complete with caching (only active when using Xml as a datasource for the datalayer) and logging.
I are Troll
|
|
|
|
|
Thank you very much. I liked your answer.
|
|
|
|
|
Just to play devils advocate, couldn't you argue that the EmployeeDBDataContext is in fact your DAL and the code snippet should be part of the BLL?
If the purpose of the DAL is to allow you to change your data source without affecting the business logic, then I would say the EmployeeDBDataContext achieves this.
"You get that on the big jobs."
|
|
|
|
|
Thank you very much. Yes, thats a good question. Actually, I spent many hours just to find out if that given code snippet should be a part of BLL or DAL. Yes, if I place that snippet in BLL, then, the auto generated LINQ to SQL data context can be the DAL. But, in my BLL, I wanted see the object, not the LINQ to SQL Data context. Because that data context is auto generated and I will have to depend on what Microsoft gives. That is much uncomfortable for me. But, I learned in many place that, Projection should not be done in DAL. Query is a Business Logic. So, the dilemma is kind of a headache and brain killing. Finally I decided to encapsulate the DataContext in DAL and the DAL will not do any projection. DAL will return a single row of a entity or a collection of entity. My BLL will use that collection of entity and use LINQ to Object to do any projection as needed. Even according to that decision, yes, you are right, the above snippet should be in BLL. I should have asked a collection of employees in DAL from BLL and then, the BLL would filter out with the email Address for the desired employee object using LINQ to Object. Hmmm Brain got jammed again
|
|
|
|
|
Definitely with Entity Framework, LINQ to SQL and alike have blurred the borders but even in more traditions architectures, the presentation can still be exposed to the entities which encapsulate the data. There is no reason why a DataGrid in the presentation can't display a collection of entities.
It looks like LINQ is querying your DB but if the DataContext is actually your DAL then LINQ is actually querying your DAL. LINQ just offers a flexible approach to communicating with the DAL as opposed to the old way of having to write a method (in the DAL), for every possible permutation the BLL may request.
So instead of the DAL deciding what the BLL can and can't request. The DAL just provides access to the data source and describes the data. The BLL is free to do what it is supposed to: decide what the presentation can and can't access.
What I have just said may be technically wrong but that's how I see it conceptually.
"You get that on the big jobs."
|
|
|
|
|
My collegues and me just had the same discussion this week.
Why do all the extra work if you could simply directly get your data from the DAL?
Well, I think that this is because sooner or later your client is going to call and they want some new functionality or improvements.
So now you have one form where your employee is called, but in a few months you will have two forms.
If you seperate your DAL from your UI you then could simply re-use that same BLL you used earlier. If you did not seperate your UI from your DAL then you will find that:
A. you need to type some code containing logic (either the LINQ query or validation logic) twice.
Or B. you'll have to make a BLL after all to not resort to solution A.
Solution A is definately not good practice and if you find your clients demands rising you will type more code multiple times.
Even worse, if the client wants the logic you now build into different forms to be slightly different, you are going to have to edit all forms that use this logic, and this is easily forgotten if your application is getting larger.
But you do not want B either, because it will cost you a lot of time (first decoupling DAL from UI and then build the extra layer).
So building that extra BLL might look like a lot of work now, but it could save you a lot of work in the future.
Hope this helped. Good luck with it
It's an OO world.
|
|
|
|
|
Thank you so much for the ideas. Yes, you are right and thats what I am realizing now. At this moment, I am avoiding the extra BLL layer, but I will keep a sharp eye when duplication of code is apparent, and only then, I will add the BLL with only the refactored common methods. So, some of my UI will call DAL and some of my UI will call BLL and over time, depending on BLL will be increased and DAL dependency will decrease.
|
|
|
|
|