Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

c# - Should I seal all classes I know shouldn't ever be used as a base class?

Should I seal all classes I know shouldn't ever be used as a base class even when there are no tangible performance or security concerns, or is this just adding cruft?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

A class which is extensible implements the feature that it can be extended -- that's a feature like any other feature of the class, and should be treated like one, no different from a method. All features should be thought through carefully to ensure that they meet the goals of the customer using the feature. Features need to be designed, implemented, reviewed for security problems, debugged, documented and maintained.

All that costs effort, and effort usually requires the outlay of money. Whose money are you spending? They might have an opinion on whether you should do this feature or not.

Basically, you have three choices:

1) Spend the money to do the feature so that you have confidence that it is correct, robust, secure and meets user needs.

2) Do none of the above but ship the feature anyway and hope that shipping an undesigned, rapidly implemented, untested, undocumented, unmaintained feature with unknown security risks doesn't harm you, your employer or your customers.

3) Seal the class. Unseal it later if you find that (1) was the right choice.

I say that (3) is good value for the money. I always seal every class I write that was not designed for extensibility.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...