On Duplication and ASP.Net
I'll be the first to admit that I
don't know much about ASP.Net UI. (I know a bit about how it works, but UI is a
mystery for me).
I needed to display a page that
would allow you to add rules to an object. There are different kinds of
objects, and each one has a different set of rules. I knew from the start that
I would probably need common functionality for all objects, but I couldn't really
write something yet, because I didn't really know what I was going to do.
So, I wrote the first page as if I
had no more pages to write, and then I wrote the second page. I did that by mainly
copying & pasting and just changing a couple of values. It was really quick
to do, and I moved to the third page using the same methods.
Now I knew what the common parts were,
it was supposed to be a simple matter to refactor it to remove duplication. It
took me a while to do it, and I'm pretty sure that it's not the "proper"
way to do it.
I've a master page for those pages, to
which I added ChildPage property that accepts a certain interface with the
operations that were different from page to page. The pages that use this
master page register themselves on the PreInit() method, and then it all comes
together. There is some non trivial logic in the master page, since it needs to
manage dynamic controls that change on the fly.
As I said, I'm not an expert, what
do you think of this solution?
Comments
Comment preview