Design pattern for a simple CRUD data driven application - asp.net

I would like to know the best practice for a designing a simple CRUD application with some screens updating various tables (like admin pages to maintain static data for an application). the simplest way would be to drag a data grid/gridview, bind it to a dataset and use a data adapter for CRUD operations. but if this application needs to be scalable, lets say to add any extra UI/business logic in future, then is there any design pattern that can help with this? should I be using an object data source control and bind it to business objects instead? or are there any better ways of doing it? should I build a complete layered application or will that be overengineering for this requirement? any examples for UI design would also be helpful. thanks.

If you are looking for a really quick and easy approach, you can look at using Dynamic Data
http://www.asp.net/dynamicdata
on top of a Linq2SQL or EF4 backend - hardly any code needed at all.

+1 Oded. No offence RKP but you might be confusing "simple" with with "effective" or "value-for-money". I also think you might want to be more clear about exactly what it is you're after: example UI designs is quite a different issue from the logical architecture. Anyway - good on you for asking.
If this is a "tactical" solution: not expected to have a long life-span, or is a quick-and-dirty dev tool then how you build it might not be such a big issue. (also beware that short-term tactical apps can end-ed being long-term strategic ones - were working on an app now that the business see as a "temporrary" tool: they see it only being used for the next 5-10 years (!)).
If it's a tool the "business users" will use, then it's quite likely they'll expect changes overtime: depending on what the app is for a simple pass-through CRUD app might only cut the mustard for a short while.
So I guess this is where your admirable desire to look at best practice comes in.
Are you familiar with OO design? A lot of the principles behind good OO design also apply at the architectural level (SOLID, Common Reuse, Common Closure, Loose Coupling, Stable Dependancies and Stable Abstraction Principles).
lets say to add any extra UI/business
logic in future
So - this is where you need to consider up-front how you will seperate concerns and allow for growth: architecture doesn't mean you have to do a big upfront design, it just means you need to have an idea of how you'll grow the application as requirements grow..
To finish:
Have a good look at the different system quality attributes and work out which ones are particularly relevant to the system. prioritise them.
I get a lot of mileage out of Dependency Inversion (The D in SOLID) - abstract out things like data access early on.
For me the other really key "best practice" is to pay attention to SRP (the S in SOLID),

http://www.asp.net/mvc is my bet. It's easy to start with and get going... You won't be dissapointed. :) StackOverflow itself is built on top of it.

Related

E-R to OO design strategies?

I'm still learning all of the powers of OO design and have much more experience in database (in particular, E-R) designs. Each time I approach a problem and attempt to come up with a design following OO strategies, my diagrams(UML classes, for example) come out looking like an ERD. I've read/heard it's then smart to map a class to each table and work from there... But this never really seems to get me anywhere and my designs have very high (bad)coupling which, as I understand, is a big "no-no" in OO.
A few google searches returned a few hits on moving from E-R to OO, but nothing that really drilled it home for me. Does anyone have any materials on this topic, or have perhaps struggled with this similar problem?
To expand just a bit, my attempted OO designs tend to move towards an implied persistent data storage element which doesn't necessarily exist in an OO design.
Thanks for any guidance!
Database Systems: A Practical Approach to... is the textbook(chapter 3~4) which I would recommend.
I think the fundamental differences in data(relational data model) and program are the main gap between E-R and OO design. You may draw database schema design in UML, but it doesn't
mean that realational data model would become any sensible meaning of OO paradigm.
The programs, from another side, focus on processing correctly with reusability discipline. The data, however, focus on persisting correctly with performance discipline.
Although there are some techniques to ease the gap(lik O-R Mapping), but the basic purposes on data/program are not totally the same.
So I think the OO is just a technique to abstract the design, not the goal of the design.
I'd suspect from what you write that you need more experience with / knowledge about some core OO design principles, in particular inheritance and polymorphism. A good understanding of these concepts can help you better understand the relationships between your objects, and the ways in which they should be coupled.
Given your comments about your OO designs moving towards an implied persistent data storage element, you might also want to look into such concepts as Aspect Oriented Programming (Spring is a great tool for this). Also, look into what an ORM such as Hibernate can do, and how it does it (this may be a bit advanced, though).
There's really only one way to learn object-oriented software design: learn it from scratch. You won't find any shortcuts for converting your knowledge of another software design method into an understanding of object-oriented design. You need to start with the basics, just like everyone else: encapsulation, abstraction, is-a and has-a relationships, etc.
E/R concept model can help you whenever you need to design relationships between an entity. You shouldn’t care how they are going to be implemented at design time : the can be converted into Class,DataTable,XML,....
what you are asking it's a bit different. In a small system or when the business logic is not too complex it is possible to have a domain model object that looks like the Data Table.In this case you can have an object per table. This pattern is called "Table Module Pattern"
http://martinfowler.com/eaaCatalog/tableModule.html
Use Nhibernate or EF or any other ORM in a system like the one mentionated earlier it's a waste of resource and time because you are adding a layer that you don't really need

What's the best way to target both WPF and Web apps?

We are currently designing a business application that has two primary requirements for it's UI:
1) run on the Desktop (WPF) for enterprise users to provide a rich user interface, interoperate with other applications, access the filesystem, work offline, work with special local hardware, etc.
2) run on ASP.NET/Ajax to provide several components of this application to customers (internet). Unfortunately Silverlight is not (yet) an option.
Even though we don't have to make the full application available on the web, some of these components are fairly complex and we would like to share as much UI code as possible with the WPF implementation.
What options do we have to reach this goal? Is there a pattern that works well with both technologies?
Update:
Thanks for the answers even though they don't include the one I was looking for! :)
I don't think UI generators are a good option. Like Eduardo pointed out you will probably end up with problems in both worlds. I will check out Sculpture though.
I've been thinking along these lines for a while now, and I've yet to come up with a great answer. That being said, here are some of my thoughts:
If you used some variation of the various MVP/MVC/MVVM UI methodologies and you were very disciplined in this approach (i.e. not mixing presentation stuff with behavior stuff), you'd probably be farther down the road.
You might consider investigating the various DSL toolkits that have cropped up, the idea being to create a simple "language" to describe your UI at a high level and generate a representation of that UI in WPF/ASPX.
Also, I ran across this recently. I have no idea how good it is. I'm planning to take a closer look when I get the chance.
Good luck!
The unfortunate truth is that Asp.net/ajax (the web in general for that matter) and WPF (and heck, let's throw WinForms in there for good measure) have very different User Interface models and what works well for one is not necessarily going to work well for another. That's not to say that you can't share logic between applications written for either technology, but, I'll make a stretch here, your UI logic is not going to be in that category.
I've been using a variation of MVVM for WPF and ASP.Net MVC most recently and I'd say they are very good fits for the technology at hand. However, while they are very similar, they have their differences and I'm not sure you could write an abstraction layer (in any decent amount of time) that could take advantage of the great features in both technologies.
Ultimately, I'd say that your best bet is to follow some SOA patterns and extract as much of your business and data access logic into common libraries as possible. Then, write separate user interfaces in WPF and Asp.net to take advantage of those common libraries. This is the approach that my company is taking at the moment, and it's working like a charm.
It may seem daunting to write your UI logic twice (once for asp.net and once for wpf), but I think it's worth it so that your code can fit the patterns and practices that best fit those technologies.
As an aside, even though Silverlight is not an option, have you considered XBAP?
If a former job we did something similar. As Daniel Pratt says, we describe our interfaces in XML and then a render will create the form, report or whatever we decided to create.
We have to provide a Javascript function to do some UI validations in the HTML render, and a call to a java function in the Swing render.
Beware that you may end with imperfect apps in both worlds.

ASP.NET Model View Presenter project structure

I am just starting a new ASP.NET project and using the MVP pattern. I did consider the MS MVC but it is not released yet and would be a big learning curve for some people on the team, so I opted for MVP now and possibly future projects MVC.
Anyway, it seems I will have a single Controller/Presenter class for every webform I have it the project. This is a lot of extra classes, essentially doubling the number of files in the web project. Is this how other people structure MVP or what are the alternatives?
This seems to be a common misconception -> "More files/classes == more complex"
The reason we chose to follow a UI separation pattern is to help separate concerns, make code easier and cheaper to change and maintain and (big, important and) we can unit test the complex parts and still keep the UI layer slim.
I'm going with the beta ASP MVC. The reason being, that while it is still only a beta (PDC very soon, that may have an impact on release and we've had 5 preview releases) it has a better framework to support this style than I could write in a reasonable time frame.
You could of course go with another framework, like castle monorail.
I think a lot of it depends but in most cases that is really the way it ends up going.
I personally use a n-tier architecture with data, business, presentation code. (Who knows what actual format I follow). I do get a lot more files than if I did everything in the aspx, but the code is much easier to manage.
To your question - I have seen many different takes on MVP and seen nothing that reduces the number of files, and I can't think of a way to reduce the number of files.
In my experience, I have reused view interfaces and even code behinds where the view structure is identical, but presenting different data. And you could also think of reusing the controllers where applicable.
I think it is worthwhile to note that having more files will be a natural consequence of moving to a more agile and test-drive development and developers will find it more and more natural as they go. (Just like some of us find it very natural having lots of methods inside a single file...)

How do you start building an ASP.NET web app?

Say for example you're getting a web app project that interacts with a database.
How do you start your development? Do you start by designing your database, drawing simple ERD and writting a create scripts? Do you start by designing the look of your of web app, maybe using photoshop, then create a master page for it? or do you start by designing your domain models, with minimal looks, and apply a preetier design later on?
Please share you thoughts on this... Cheers...
You start by deciding which way you start. No but really, it depends on too much factors to have a general answer. Do you develop using concepts of agile development, are there specified functional designs, did the client give you strict requirements, what is your own experience etc..
Generally we start by developing our business objects first, then creating views for them using sample data / fake databases or sometimes even plain text files. From there, we start filling in the bits and pieces. If not all requirements are set, it's best to keep the database outside your development as long as possible. That way you prevent yourself from having to change your db, sprocs and interaction with your db everytime.
I tend to do the last of those ideas, "start by designing your domain models, with minimal looks, and apply a preetier design later on" I like to make my application, of any kind, does what I want it to do before I spend time on making it look pretty.
Figure out how the users need to interact with your site first. What are they needing to achieve?
Let this define you ERD and the database model will quickly follow.
Then, when you actually start coding you'll be heading in the right direction.
Many will also say, write your Unit Tests first. It's hard to do but often worth it.
UI and DB, but it depends which one is really first. The UI is a very important thing because your customer has to work with it in the end (some say there might be developers who sometimes forget...). The database design is a very good way to put (some) structure in all the business needs which aren't always specified in a strictly and well structured way.
This is junior's experience, I've been working in development since 2004, beginning with a 4-year-apprenticeship in a development company.
Cheers,
Matthias
I start with the functional UI, moving from there to the business layer and db (usually in tandem to start with). Design is normally provided in some respect by the client, so I try to apply that early on, without letting it get in the way. I like to get the domain sorted out in one step (minor changes are acceptable later), and I create my scripts as I get to them in my code.
It sounds like a bit of a runaround, but it works for me.
I definitely start with a UI Prototype.
Clients never know what they really want untill they see it.
A simple change on a UI can translate to a dramatic change in the core components of your system. So rather let the user play with a pretty prototype until they are confident it's what they looking for, and then dive into system objects and database design.
With regards to Database and System objects, I find it difficult to decide which way to go. Going database first definitely influences my class design, so I try go object first as much as possible. It turns into a more human design IMO
Depends on the Project Id' say.
Usually it's good to have a Photoshop mockup to show your client what they're getting.
On small no-maintenance projects I try to start by modeling the database first to get a better overview on the structure. Then it's usually quite easy to create a Web Application around it.
On bigger projects I usually start by creating (basic) prototypes of critical pieces of the software. I then show those to clients and afterwards throw them away. They're just there to help me understand the upcoming challenges better.
But as said, it's a matter of taste and project.

Productivity gains of using CASE tools for development

I was using a CASE called MAGIC for a system I'm developing, I've never used this kind of tool before and at first sight I liked, a month later I had a lot of the application generated, I felt very productive and ... I would say ... satisfied.
In some way a felt uncomfortable, cause, there is no code and everything I was used to, but in the other hand I could speed up my developing. The fact is that eventually I returned to use C# because I find it more flexible to develop, I can make unit testing, use CVS, I have access to more resources and basically I had "all the control". I felt that this tool didn't give me confidence and I thought that later in the project I could not manage it due to its forced established rules of development. And also a lot of things like sending emails, using my own controls, and other things had their complication, it seemed that at some point it was not going to be as easy as initially I thought and as initially the product claims. This reminds me a very nice article called "No Silver Bullet".
This CASE had its advantages but on the other hand it doesn't have resources you can consult and actually the license and certification are very expensive. For me another dissapointing thing is that because of its simplistic approach for development I felt scared on first hand cause of my unexperience on these kind of tools and second cause I thought that if I continued using it maybe it would have turned to be a complex monster that I could not manage later in the project.
I think it's good to use these kind of solutions to speed up things but I wonder, why aren't these programs as popular as VS.Net, J2EE, Ruby, Python, etc. if they claim to enhance productivity better than the tools I've pointed?
We use a CASE tool at my current company for code generation and we are trying to move away from it.
The benefits that it brings - a graphical representation of the code making components 'easier' to pick up for new developers - are outweighed by the disadvantges in my opinion.
Those main disadvantages are:
We cannot do automatic merges, making it close to impossible for parallel development on one component.
Developers get dependant on the tool and 'forget' how to handcode.
Just a couple questions for you:
How much productivity do you gain compared to the control that you use?
How testable and reliant is the code you create?
How well can you implement a new pattern into your design?
I can't imagine that there is a CASE out there that I could write a test first and then use a CASE to generate the code I need. I'd rather stick to resharper which can easily do my mundane tasks and retain full control of my code.
The project I'm on originally went w/ the Oracle Development Suite to put together a web application.
Over time (5+ years), customer requirements became more complex than originally anticipated, and the screens were not easily maintainable. So, the team informally decided to start doing custom (hand coded) screens in web PL/SQL, instead of generating them using the Oracle Development Suite CASE tools (Oracle Designer).
The Oracle Report Builder component of the Development Suite is still being used by the team, as it seems to "get the job done" in a timely fashion. In general, the developers using the Report Builder tool are not very comfortable coding.
In this case, it seems that the productivity aspect of such CASE tools is heavily dependent on customer requirements and developer skill sets/training/background.
Unfortunaly the Magic tool doesn't generates code and also it can't implement a design pattern. I don't have control over the code cause as i stated before it doesn't have code to modify. Te bottom line is that it can speed up productivity in some way but it has the impossibility to user CVS, patterns also and I can't control all the details.
I agree with gary when he says "it seems that the productivity aspect of such CASE tools is heavily dependent on customer requirements and developer skill sets/training/background" but also I can't agree more with Klelky;
Those main disadvantages are:
1. We cannot do automatic merges, making it close to impossible for parallel development on one component.
2.Developers get dependant on the tool and 'forget' how to handcode.
Thanks

Resources