Web Project Class Architecture

I think this is a good question for here but I’m not 100% sure. Please flag if it’s too vague.

I’ve worked on many websites where common framework classes are overridden.

Since I work mostly in .net these days examples would include Page, Masterpage, UserControl, DbContext ect. I believe this could apply to any language though.

Sometimes I can see why it’s done, I overrode entity framework’s DbContext to include some logging code.

Allot of the time though I don’t see why these base classes were created. Because I’ve inherited most of the sites I can’t really ask why.

My question: Is it a good idea/practice when creating a new site to Override the common framework classes mentioned above? Would doing so be considered more of an old style?

No it is not a good idea. Unless you are doing a very special job you don’t need overriding framework main classes. Problem with rich frameworks i.g. .net and java is understanding the framework takes time based on the parts you mostly use. Only after that, frameworks reduce your work load. These frameworks are designed by top engineers so if you need to overwrite a lot of them, probably you don’t know where the feature you are looking for is or how to implement it. I read somewhere time is like money:

  1. You can spend it (doing something)
  2. You can save it (using proper tools)
  3. You can invest it (spending some of it now, to save much more later)

When you create an application, most of what you are doing ought to be framework independent. The framework really ought to be a detail on the side, not an integral part at the centre of your application. Think of it as a delivery mechanism or so. Same goes for databases and whatnot. If you create proper boundaries, you’ll be able to switch database, UI, routing framework, etc, without having to rewrite your application.

This means that in general it is not a good idea to have your app work with classes that inherit from things outside of your package boundary. Hard to create a tighter coupling or greater dependency then inheriting. Esp mixing in logging there seems wrong.

On the logging topic – be very careful on what logging code you put in a DbContext. If this DbContext takes a logger using some nice Logger interface, then it can work. Else you are probably violating the Single responsibility principle.

It’s not a good idea to override framework classes, even when it’s supposed to do by authors of the framework. “Always prefer composition over inheritance” – widely known rule.
Overriding code of framework makes your code more dependent and tightly coupled with code of framework.

And just to note: “Masterpage” name looks like “God-object” antipattern case.

In computer programming, a software framework is an abstraction in which software providing generic functionality can be selectively changed by additional user-written code, thus providing application-specific software. A software framework is a universal, reusable software platform to develop applications, products and solutions. Software frameworks include support programs, compilers, code libraries, tool sets, and application programming interfaces (APIs) that bring together all the different components to enable development of a project or solution.

Framework is a set of classes and utilities which has some basic functions but at the same time it is not standalone. Framework has many hooks which you can override to your own logic and has many holes which you must fill up with your own logic. Like interface and abstract class for example. Unless you are doing special work which need your own logic you are free to use the basic general framework logic.

For an example, we can use ASP.NET membership system in our ASP.NET application. It will act with the general membership logic. But if we need a special situation which is special for your application then you have to inherit and override the membership provider classes to give your own implementation.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật