inheritance

asp.net Can I force every page to inherit from a base page? Also should some of this logic be in my master page?

房东的猫 提交于 2020-01-02 12:01:32
问题 I have a web app that has a base page. Each page needs to inherit from this base page as it contains properties they all need as well as dealing with the login rights. My base page has some properties, eg: IsRole1, IsRole2, currentUserID, Role1Allowed, Role2Allowed. On the init of each page I set the properties "Role1Allowed" and "Role2Allowed" Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init Role1Allowed = True Role2Allowed= False End Sub The

Non-designated initialiser inheritance from Objective C classes

守給你的承諾、 提交于 2020-01-02 11:20:12
问题 Having come across problems when sub-classing UIKit classes and adding immutable variables to them, I made a test project to figure out what was going on. My conclusion is that if: we have an Objective C class, which inherits from another class, with its own designated initialiser (implicit or explicitly annotated) in its initialiser , it calls [self initWithXX] where initWithXX is an init method on the superclass we subclass this class in Swift , adding an immutable property (which obviously

Pattern to extend classes without modifying them (or knowing implementation details) (c#)

久未见 提交于 2020-01-02 10:28:30
问题 I am modifying some code that sits between two established layers, and am having trouble figuring out what the best design is. Currently the code calls a file access library, and returns an object to the caller. I need to extend the returned object to add some custom dispose functionality. I don't have access to the definitions of the passed objects (some are filestreams, for example) It would save me a lot of work if I could create a child instance that behaves like a base instance, and can

XJC Java class generation for <xs:choice> element which is not unbounded

笑着哭i 提交于 2020-01-02 10:04:39
问题 After this similar question yesterday I have another question concerning inheritance in XML schema and XJC bindings. Given the following choice element such that Book and Journal have a common parent type ( Publication ). <xsd:choice > <xsd:element name="Book" type="Book" /> <xsd:element name="Journal" type="Journal" /> </xsd:choice> The Java class properties which are generated are like: private Book book; private Journal journal; Since <xsd:choice> means that there might be either a Book or

constructor calling order with composition

巧了我就是萌 提交于 2020-01-02 08:54:49
问题 I have a class A and Class B . Class C derives from Class B and has Class A object as composition . http://ideone.com/JGT48M #include "iostream" using namespace std; class A { int i; public: A(int ii) : i(ii) { cout << "\n Constructor of A is called \n"; } ~A() { cout << "\n destructor of A is called \n"; } void f() const {} }; class B { int i; public: B(int ii) : i(ii) { cout << "\n Constructor of B is called \n"; } ~B() { cout << "\n destructor of B is called \n"; } void f() const {} };

Creating a Non-Instantiable, Non-Extendable Class

北城以北 提交于 2020-01-02 08:41:12
问题 I want to make a class to group some static const values. // SomeClass.dart class SomeClass { static const SOME_CONST = 'some value'; } What is the idiomatic way in dart to prevent dependent code from instantiating this class? I would also like to prevent extension to this class. In Java I would do the following: // SomeClass.java public final class SomeClass { private SomeClass () {} public static final String SOME_CONST = 'some value'; } So far all I can think of is throwing an Exception ,

Java abstract method with abstract parameter and inheritance

大兔子大兔子 提交于 2020-01-02 08:13:59
问题 I recently fumbled into a problem with an API and an implementation where the following type of code appeared: The API is an abstract class: public abstract class A { public A sum(A a) { System.out.println("A.sum(A) called"); return null; } } The implementation is a simple class: public class B extends A { public B sum(B b) { System.out.println("B.sum(B) called"); return null; } } When it comes to using it I write: public class Main { public static void main(String args[]) { B b = new B(); A

Java generics parameters with base of the generic parameter

久未见 提交于 2020-01-02 08:13:10
问题 I am wondering if there's an elegant solution for doing this in Java (besides the obvious one - of declaring a different/explicit function. Here is the code: private static HashMap<String, Integer> nameStringIndexMap = new HashMap<String, Integer>(); private static HashMap<Buffer, Integer> nameBufferIndexMap = new HashMap<Buffer, Integer>(); // and a function private static String newName(Object object, HashMap<Object, Integer> nameIndexMap){ .... } The problem is that I cannot pass

Protected members in a superclass inaccessible by indirect subclass in Java

纵然是瞬间 提交于 2020-01-02 07:24:43
问题 Why is it that in Java, a superclass' protected members are inaccessible by an indirect subclass in a different package? I know that a direct subclass in a different package can access the superclass' protected members. I thought any subclass can access its inherited protected members. EDIT Sorry novice mistake, subclasses can access an indirect superclasses' protected members. 回答1: Perhaps you're a little confused. Here's my quick demo and shows an indirect subclass accessing a protected

Public static methods - a bad sign?

不羁的心 提交于 2020-01-02 07:20:14
问题 I've just read this article here: http://hamletdarcy.blogspot.com/2008/04/10-best-idea-inspections-youre-not.html, and the last bit in particular got me thinking about my code, specifically the advice: What in the world is a public method doing on your object that has no dependency on any fields within the object? This is certainly a code smell. The problem is that the "auto-fix" for the inspection is to apply the static keyword. Nooooo. That's not what you want to do. A public method without