sealed

Should classes still be sealed as a recommendation? [closed]

给你一囗甜甜゛ 提交于 2019-12-23 08:02:12
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . I know this is "technically" a duplicate of this question. Should I recommend sealing classes by default? But I'm asking it again because apparently the recommendation has changed 1 with the times though I can't find anything in the last few years about it or about the fact

Why do WinRT types have to be sealed?

自古美人都是妖i 提交于 2019-12-22 03:43:58
问题 In several places (e.g. "Creating Windows Runtime Components for JavaScript, in C# and Visual Basic" on MSDN), I've seen it specified that, if you write a class in .NET that you want to use from JavaScript, then you must make it a sealed class. This seems like an arbitrary restriction. Why can JavaScript only work with sealed classes? 回答1: Windows runtime objects exposed to JavaScript applications are sealed from a JavaScript perspective - you can't add expando properties to WinRT objects.

Python's equivalent of .Net's sealed class

瘦欲@ 提交于 2019-12-20 14:45:41
问题 Does python have anything similar to a sealed class? I believe it's also known as final class, in java. In other words, in python, can we mark a class so it can never be inherited or expanded upon? Did python ever considered having such a feature? Why? Disclaimers Actually trying to understand why sealed classes even exist. Answer here (and in many, many, many, many, many, really many other places) did not satisfy me at all, so I'm trying to look from a different angle. Please, avoid

What is an internal sealed class in C#?

本秂侑毒 提交于 2019-12-20 09:08:30
问题 I was looking through some C# code for extending language support in VS2010 (Ook example). I saw some classes called internal sealed class What do these do? Would one use them? 回答1: It is a class that: internal : Can only be accessed from within the assembly it is defined (or friend assemblies). sealed : Cannot be inherited. Marking classes as internal is a way of preventing outside users of an assembly from using them. It's really a form of design encapsulation and IMHO it is good practice

Can we declare sealed method in a class

限于喜欢 提交于 2019-12-19 10:19:58
问题 class X { sealed protected virtual void F() { Console.WriteLine("X.F"); } sealed void F1(); protected virtual void F2() { Console.WriteLine("X.F2"); } } In the above code there is compile time error : X.F()' cannot be sealed because it is not an override X.F1()' cannot be sealed because it is not an override Does it mean we can only apply the sealed keyword whey we have to override some methods? 回答1: Well, sealed keyword prevents method from being overriden , and that's why it doesn't make

Purpose of final and sealed

余生长醉 提交于 2019-12-18 05:48:20
问题 Why would anyone want to mark a class as final or sealed? 回答1: According to Wikipedia, "Sealed classes are primarily used to prevent derivation. They add another level of strictness during compile-time, improve memory usage, and trigger certain optimizations that improve run-time efficiency." Also, from Patrick Smacchia's blog: Versioning: When a class is originally sealed, it can change to unsealed in the future without breaking compatibility. (…) Performance: (…) if the JIT compiler sees a

Why aren't classes sealed by default?

给你一囗甜甜゛ 提交于 2019-12-17 16:14:07
问题 I was just wondering, since the sealed keyword's existence indicates that it's the class author's decision as to whether other classes are allowed to inherit from it, why aren't classes sealed by default, with some keyword to mark them explicitly as extensible? I know it's somewhat different, but access modifiers work this way. With the default being restrictive and fuller access only being granted with the insertion of a keyword. There's a large chance that I haven't thought this through

How to define sealed class in C++?

限于喜欢 提交于 2019-12-17 10:24:17
问题 How to stop the class to be inherited by other class. 回答1: C++11 solution In C++11, you can seal a class by using final keyword in the definition as: class A final //note final keyword is used after the class name { //... }; class B : public A //error - because class A is marked final (sealed). { // so A cannot be derived from. //... }; To know the other uses of final, see my answer here: What is the purpose of the "final" keyword in C++11 for functions? C++03 solution Bjarne Stroustrup's

How to define sealed class in C++?

℡╲_俬逩灬. 提交于 2019-12-17 10:22:42
问题 How to stop the class to be inherited by other class. 回答1: C++11 solution In C++11, you can seal a class by using final keyword in the definition as: class A final //note final keyword is used after the class name { //... }; class B : public A //error - because class A is marked final (sealed). { // so A cannot be derived from. //... }; To know the other uses of final, see my answer here: What is the purpose of the "final" keyword in C++11 for functions? C++03 solution Bjarne Stroustrup's

C# sealed class vs. no public constructor

三世轮回 提交于 2019-12-13 08:26:32
问题 I am currently trying to get deeper into the .NET framework. I ran across an error while I was wondering if I could create two CommandManagers: Cannot create an instance of CommandManager because it has no public constructors. Obviously it means: don't do it, and it might not even make sense to have two of them. Now I came across an other error before with the message: Cannot create an instance of ... because it is sealed The effect is the same in prohibiting but what is the difference. Why