• RELEVANCY SCORE 5.18

    DB:5.18:Subclass Vs Concrete Class fs




    Hi,

    What is the exact difference between subclass and concrete class?

    What is the need in subclassing abstract class to again abstract class?

    Thanks in Advance,
    venu.

    DB:5.18:Subclass Vs Concrete Class fs

    Hi,

    U mean to say Concrete classes are instantiatable
    and every concrete class is a subclass of some
    super class.Plz clarify me if i am wrong.That's correct. But it's also true that every class--both concrete and abstract--is a subclass of some superclass, except Object which has no superclass.

    NOTE: The following is simply provided in the interest of completeness because I'm a ballsniffing pedant. It's not that important to what you're asking about, and may just cause more confusion. Feel free to ignore it.

    Also, it's possible to make a concrete class non-instantiable by having a single private constructor and throwing an exception from it, but that's a runtime issue--the compiler will let you insstantiate the class (only from within itself if the c'tor is private).

  • RELEVANCY SCORE 3.81

    DB:3.81:Class Vs Subclass c7




    What is the purpose of a subclass and when should a subclass be used?

    DB:3.81:Class Vs Subclass c7

    Thanks! Now that makes alot of sense.

  • RELEVANCY SCORE 3.53

    DB:3.53:Abstract Class Extending An Interface. Please See kd




    Hi,

    Look at the flwg code.

    I am using an Interface with 2 methods,
    2 abstract classes and concrete Subclass.

    My Question is:

    1.When is it feasible to use such a kind of pattern? (ie
    define an interface,and then define abstract classes
    extending this interface,and then defining a concrete
    subclass extending the abstract class).

    When is this design applicable?

    Is there an advantage of using this? I have seen this kind of design
    in the Collection framework.

    interface IFly{
    void accelerate(int speed);
    void slowDown(int speed);
    }

    abstract class SuperHero implements IFly{
    }

    abstract class JusticeLeagueSuperHero extends SuperHero{

    public void accelerate(int speed){
    System.out.println("Accelerating: " + speed);
    }

    }

    class SomeMoreSpecificSuperHero extends JusticeLeagueSuperHero{

    public void slowDown(int speed){
    System.out.println("Slowing Down " + speed);
    }
    }

    public class InterfaceAbstractTest{
    public static void main(String args[]){

    SomeMoreSpecificSuperHero sM = new SomeMoreSpecificSuperHero();
    sM.slowDown(100);
    sM.accelerate(200);

    }

    }

    DB:3.53:Abstract Class Extending An Interface. Please See kd

    Dr Clap,

    Why not define the null methods in the class that
    implements the interface having multiple
    methods?

    ie,if ClassA implements InterfaceA which has several
    methods,I can define all the methods
    in ClassA without having any implementation(null
    methods).

    So why do I need to define an abstract class extending
    the interface and then my concrete class
    extending the abstract class?Certainly you can do that. But then you'll find you have dozens of classes where you provide default implementations of the methods required by the interface. Refactoring this situation yields an abstract class that provides those default implementations, and your dozens of classes become subclasses of that abstract class with smaller code.

  • RELEVANCY SCORE 3.45

    DB:3.45:Quick Interface Question 39


    I have an abstract class A which implements a single interface I.

    The I interface contains a single method, which is actually implemented by the abstract class A (ie, implementation is not deferred to a subclass for the method defined by the interface).

    Now I create a subclass S of A, which is a concrete class. I implement all the abstract methods of A.

    Eclipse still gives me an error, saying that S must implement the method defined by interface I.

    Why is it doing this, if that method has already been implemented by my superclass A?

    Thanks,
    hqd

    DB:3.45:Quick Interface Question 39

    please ignore********In the future (assuming the forum hasn't broken) note that you could have simply edited away the original post since nobody had replied to it (yet).

  • RELEVANCY SCORE 3.43

    DB:3.43:Subclass Question jd


    hey all,

    silly question probably, I have a private instance variable set within a class, how would i access this private instance within a subclass without changing it to public.

    regards,
    Sjakkie

    DB:3.43:Subclass Question jd

    write a public getter to access that variable in super class and call that getter in sub class

  • RELEVANCY SCORE 3.33

    DB:3.33:Overriding An Initial Value In A Subclass? 1s



    Yes you can..

    class BaseClass : MonoBehaviour
    {
    public int someValue = 5;
    }



    ...

    class SubClass : BaseClass
    {
    public void Reset()
    {
    someValue = 10;
    }
    }

    DB:3.33:Overriding An Initial Value In A Subclass? 1s


    I came here because while I knew how to override in inheriting classes, I couldn't find a way to access the overridden value in the inspector. I just realized while reading the comments that all I had to do was not override the variable in the inheriting class. AS long as I don't do this, it shows up in the inspector.


    My former code:


    Base class: public abstract int ScoreValue { get; set; }


    Inheriting Class: public override int ScoreValue { get {return 15;} //the value you want to set set {} }

  • RELEVANCY SCORE 3.27

    DB:3.27:Overriding The Default Windows Forms Irootdesigner az


    I would like my VS Package to somehow replace the IRootDesigner that is created when designing a Windows Form.I realise I can do this by subclassing Form, and placing a DesignerAttribute on the class declaration - however I dont want to have to subclass - I want to force my designer to be used instead of the actually defined on the Form class.

  • RELEVANCY SCORE 3.24

    DB:3.24:Abstract Wsdl Vs Concrete Wsdl fm


    how can we say that WSDL is concrete or abstract?what is difference b/w both WSDLs?what is the purpose of concrete and abstract wsdl?

    DB:3.24:Abstract Wsdl Vs Concrete Wsdl fm

    see :
    http://blogs.oracle.com/aia/entry/aia_11g_best_practices_for_dec
    http://docs.oracle.com/cd/E17904_01/doc.1111/e17364/bestpractices.htm#BABCGHEH

    http://eai.ittoolbox.com/groups/technical-functional/tibco-l/abstractconcrete-wsdl-1091495

    abstract wsdls can be used on designtime, so in that case the backend service don't have to be online to implement your process.
    on runtime the concrete wsdl will be used to lookup for example the actual endpoint (service) and bindings

  • RELEVANCY SCORE 3.20

    DB:3.20:How To Get The Subclass From A Super Class( Or Interface) 83


    hi,
    I want to get subclass from a super class (or a interface), how to do that? the subclass of a interface means the class implementing the interface.

    for example;
    List ls;

    I want to get the subclass of ls, i.e., LinkedList, Stack, Vector......

    AbstractList al;
    the subclass of al, i.e., ArrayList, Vector.......

    thanks
    Aiwu

    DB:3.20:How To Get The Subclass From A Super Class( Or Interface) 83

    List ls = new ArrayList();Since ls has been declared as a List we can only use List methods
    with it. This is a good thing because we might later want to change
    it to some other sort of List.

    I want to get subclass from a super class (or a interface), how to do
    that?The instance of the subclass declared above did not really come
    from the super class. A class "knows nothing" about its
    subclasses: many sub classes would not even exist at the time
    the class was written.

  • RELEVANCY SCORE 3.15

    DB:3.15:Knowing The Object Type? Is This Possible? dk


    Can we know the type of the object created ? Is there any method
    that lets you know the type of object?

    For example:

    class Superclass{
    }

    class Subclass extends Superclass{

    }

    class TestInheritance{
    public static void main(String[] args){

    Subclass subClass = new Subclass();

    }

    }Now,Subclass is of type Subclass and also of type Superclass.
    Right?

    IS there any way or method I can find out the type of Subclass? ie
    Subclass is of type 'Subclass' and 'Superclass'.

  • RELEVANCY SCORE 3.09

    DB:3.09:Frustrated By An Abstract Class "Selector"? 3j


    JDK1.4.2 As doc said, this class is abstract, and its method "isOpen" is abstract, which means it's empty and to be implemented by a "Concrete" subclass. However, I tested it by below code, and found out that "isOpen" is not empty!

    import java.io.*;
    import java.nio.channels.*;

    public class SelectorTest{
    public Selector sel = null;
    public void init(){
    try{
    sel = Selector.open();
    }
    catch(Exception e){}
    }
    public static void main(String arg[]){
    SelectorTest t = new SelectorTest();
    t.init();
    System.out.println("true?"+t.sel.isOpen());
    }
    }

    The output is "true?true"

    Anybody can explain this? Thank you!

    DB:3.09:Frustrated By An Abstract Class "Selector"? 3j

    Good point! I got this.

    sun.nio.ch.WindowsSelectorImpl

    So, can I assume this hidden subclass implements all
    abstract methods of Selector?Yes. It must. If you're getting an instance of a class, then it (or a parent class) must implement all abstract methods from any ancestor classes or implemented interface. If it doesn't, it can't be instantiated.

  • RELEVANCY SCORE 3.07

    DB:3.07:Abstract Calendar Returns Gregoriancalendar? az


    Hi,

    Could someone explain the OO perspective and/or design pattern used by Calendar.getInstance() which returns an instance of a subclass: GregorianCalendar?

    How could the abstract Calendar be aware that a concrete subclass exists?

    Thanks.

    DB:3.07:Abstract Calendar Returns Gregoriancalendar? az

    It is a pattern called the abstract factory, there is a nice example on Wikipedia. Basically one method call can yield different results based on anything from a value from a property file, your IP or any other value which can vary from client to client.

  • RELEVANCY SCORE 3.06

    DB:3.06:Abstract Classes 88


    Ok, i think i understand better about abstract classes now. Just to make sure, Abstract classes and methods are implimented by their subclasses. This is the part i need clarifying. The subclasses can be instantiated by concrete classes which do not extend from them? e.g.
    So i have an abstract class called Person which has a constructor which creates a Person Object.
    I have a subclass of Person called Borrower which also has a constructor that is passed values. This class is not abstract.
    I then have a concrete class call StudentBorrower which does not extend any of the above two classes. In order for me to create a Person object in this class, i have to instantiate the Borrower class dont i and not the abstract Person class? e.g.
    Borrower.Person(...) (this syntax doesnt work though, not sure the exact way to do this)

    DB:3.06:Abstract Classes 88

    nick2price wrote:
    Ok, i think i understand better about abstract classes now. Just to make sure, Abstract classes and methods are implimented by their subclasses. This is the part i need clarifying. The subclasses can be instantiated by concrete classes which do not extend from them? e.g.That's such a confusion of misused terminology that I can't even call it wrong.

    So i have an abstract class called Person which has a constructor which creates a Person Object.No. Constructors do not create objects. A c'tor puts a newly created object into a valid initial state.

    I have a subclass of Person called Borrower which also has a constructor that is passed values. This class is not abstract.Okay, it's a concrete class.

    I then have a concrete class call StudentBorrower which does not extend any of the above two classes. Okay. But it sounds odd that Borrower would extend Person but StudentBorrower would not extend Borrower or possibly Person.

    In order for me to create a Person object in this class, i have to instantiate the Borrower class dont i and not the abstract Person class? Yes. You cannot instantiate abstract classes. You can only instantiate concrete classes. Every Borrower IS-A Person, though, so if you have a Borrower object, you also have a Person object.
    .
    Borrower.Person(...) (this syntax doesnt work though, not sure the exact way to do this)Person p = new Borrower(..);
    // or
    Borrower b = new Borrower(...);Either way you have exactly the same object--a Borrower object, which is also a Person object. The only difference is whether you are referring to it through a Person reference or Borrower reference. Most of the time it shouldn't matter, but it's generally preferable to use as abstract a reference as meets your needs. (Google "programing to the interface" for details.)

  • RELEVANCY SCORE 3.06

    DB:3.06:Subclass Mapping With Hibernate 1a


    Hello everyone,

    I have a superclass Category:

    public class Category implements Serializable, ComparableObject {

    private int id = 0;
    private String title = null;
    private String description = null;
    private Category parentCategory;
    private SetCategory childCategories = new HashSetCategory();
    private Date creationDate = new Date();

    ..............
    }and two subclasses (ItemCategory and UserCategory):

    public class ItemCategory extends Category {

    public ItemCategory() {
    super();
    }

    }

    public class UserCategory extends Category {

    public UserCategory() {
    super();
    }

    }Those two sublasses does not add behaviour, they only share attributes.

    Then i have two tables in my databse:

    user_category
    id
    title
    description
    id_parent
    creation_date

    item_category
    id
    title
    description
    id_parent
    creation_date

    i could have just one table, but i think that this is more appropiate because the stored information is different.

    My problem is that i dont know which inheritance mapping strategy is more appropiate: table per class hierarchy, table per subclass or table per concrete class.

    Could someone give me a hint?

    Thanks in advance

    DB:3.06:Subclass Mapping With Hibernate 1a

    Ok thanks, will try and implement all. Yes, learning hibernate is the main goal now, but i would like to make a good design also :). I think i finally will use just a Category class and maybe a CategoryType to distinguish between diferent categories.

    Thanks again

  • RELEVANCY SCORE 3.05

    DB:3.05:Ramifications Of Extending Subclass By Creating Abstract Method In Base ap


    What r the ramification of extending subclass functionality by creating abstract method in base class?

    DB:3.05:Ramifications Of Extending Subclass By Creating Abstract Method In Base ap

    What r the ramification of extending subclass functionality by creating abstract method in base class?

  • RELEVANCY SCORE 3.05

    DB:3.05:Appidtool Id-Class Generation Changed ? fx


    Hi,

    is it possible that the generation of Id-classes via appidtool changed in
    3.1.3 due to adding support for additional primary key fields in
    subclasses.

    I got an abstract base-class Person. A concrete (non-abstract) PersonId
    should be used for all subclasses of Person.

    When I run the appidtool from Kodo 3.1.2 the generated PersonId class was
    not declared as an abstract class.

    Since 3.1.3 the generated PersonId class is declared as an abstract class.

    At them moment I have to remove the abstract keyword from PersonId by hand
    and then everything runs as before.

    Must I use for every subclass of Person an extra concrete/non-abstract
    Id-Class ?

    Thanks a lot, Matthias

    Here is the exception
    ---------------------

    [java] java.lang.InstantiationError: xxx.yyy.zzz.jdo.business.PersonId
    [java] at
    xxx.yyy.zzz.jdo.business.Student.jdoNewObjectIdInstance(Student.java)
    [java] at
    kodo.runtime.PersistenceManagerImpl.makePersistentInternal(PersistenceManagerImpl.java:1934)
    [java] at
    kodo.runtime.PersistenceManagerImpl.makePersistent(PersistenceManagerImpl.java:1881)
    [java] at
    xxx.yyy.zzz.jdo.application.TestCase1.test(TestCase1.java:73)
    [java] at
    xxx.yyy.zzz.jdo.application.TestCase1.main(TestCase1.java:88)

    JDO-Metadata:
    -------------
    class name="Person" identity-type="application" objectid-class="PersonId"
    .
    .
    .
    /class

    Mapping-Metadata:
    -----------------

    class name="Person"
    jdbc-class-map type="horizontal"/
    /class

    Class-Definition:
    ------------------
    public abstract class Person{
    .
    .
    .
    }

    DB:3.05:Appidtool Id-Class Generation Changed ? fx

    This is a known bug in 3.1.3's appidtool. It will be fixed in the next
    release (it has already been corrected internally). The workaround is
    either to make your base class non-abstract so that the tool generated a
    non-abstract id class, or to just change the app id class once it is
    generated. If I were you, I'd do the latter and check in my app id
    class code to my source control system. There's no reason it should be
    generated on every build.

  • RELEVANCY SCORE 3.04

    DB:3.04:Making A Template kf


    I want to make a template for a kind of class. But I don't just want to specify the interface--I want to control 80% of the action of the class. Specifically I want to
    1. Specify an abstract constructor or something like it. The best I've come up with on this so far is making the constructor always throw an exception unless it's overridden.
    2. Specify some static final fields. My best effort on this so far is making some abstract functions that are intended to return only constants, but I have no way to enforce that they return only constants and it seems like a bad solution.
    3. I'd like to have an abstract nested class within this template, with an abstract function inside the nested class to be implemented by concrete subclasses of the outer class. But when I try to do this, it (eclipse) doesn't give me an error if I don't implement the nested class when I make a concrete subclass.

    What would be best is if I could make it so Eclipse says a concrete subclass has a syntax error until all the things I want implemented about this class, actually are implemented.

    DB:3.04:Making A Template kf

    Being more specific, this is the class I have so far:
    package machines;

    import java.util.Vector;

    /**
    * Provides the format for a single tile on the ground
    *
    */

    public abstract class Tile
    {
    /**Neighbors of the Tile. Subclasses of Tile should
    * define final ints that name the indices of this vector
    * from 0 to NEIGHBORS - 1, e.g. NORTH SOUTH EAST WEST
    */
    VectorTile neighbors;
    private boolean initialized = false;
    /** Specified number of neighbors*/
    private VectorAnt antsOnTile;
    private VectorMessage messageSet;

    public Tile(){}

    /**
    * @return the number of neighbors this tile should have
    */
    protected abstract int numNeighbors();

    public void intializeTile(VectorTile neighbors) throws TileException
    {
    if(neighbors == null || neighbors.size() != numNeighbors() || neighbors.indexOf(null) = 0 || initialized == true)
    throw new TileException();
    this.neighbors = neighbors;
    initialized = true;
    }

    public void receiveAnt(Ant a)
    {
    antsOnTile.add(a);
    }

    public void sendAnt(int neighbor) throws TileException
    {
    if(neighbor numNeighbors() || neighbor 0)
    throw new TileException();
    Ant a = antsOnTile.remove(0);
    if(a == null)
    throw new TileException();
    neighbors.get(neighbor).receiveAnt(a);
    }

    public void receiveMessage(Message a)
    {
    messageSet.add(a);
    }

    public void sendMessage(int neighbor, Message m) throws TileException
    {
    if(neighbor numNeighbors() || neighbor 0)
    throw new TileException();
    neighbors.get(neighbor).receiveMessage(m);
    }

    public class TileException extends Exception
    {
    static final long SerialVersionUID = 2L;
    }
    public class Message
    {
    String name;
    public Message(String name)
    {
    this.name = name;
    }
    }

    public abstract class FiniteStateMachine
    {

    class State
    {
    String name = new String();
    public String toString()
    {
    return name;
    }
    }
    /** the output of a step of the FSM */
    class Output
    {
    State q;
    VectorMessage m;
    // ants contains true at index i iff this fsm is sending
    // an ant to neighbor i this step
    VectorBoolean ants;
    }

    final VectorState Q;
    State q;

    /**
    * Always throws a tile exception
    * a subclass should override this to specify
    * the set of states Q and a start state
    * @throws TileException
    */
    public FiniteStateMachine() throws TileException
    {
    Q = null;
    q = null;
    throw new TileException();
    // this must be filled in by the user
    // Initialize all states
    // Initialize the start state
    }

    /**
    * The next state function for the FSM
    * @param qi the current state
    * @param m the current queued messages
    * @return an Output object containing the new state and new messages
    */
    abstract Output lambda(State qi, VectorMessage m);

    public void update() throws TileException
    {
    if(messageSet == null || messageSet.size() != numNeighbors() || messageSet.indexOf(null) = 0)
    throw new TileException();
    Output o = lambda(q, messageSet);
    messageSet = null;
    q = o.q;
    if(o.m == null || o.m.size() != numNeighbors() || o.m.indexOf(null) = 0)
    throw new TileException();
    if(o.ants == null || o.ants.size() != numNeighbors() || o.ants.indexOf(null) = 0)
    throw new TileException();
    for(int i = 0; i numNeighbors(); i++)
    {
    sendMessage(i, o.m.get(i));
    if(o.ants.get(i).booleanValue())
    sendAnt(i);
    }
    }
    }
    }I want someone subclassing it to have to fill in Tile.FiniteStateMachine.lambda(), specify a number of neighbors (optimally a static final int, but as you see what I have is a function), and specify a constructor for FiniteStateMachine that fills in Q and initializes q to a member of Q. Everything else I want to have fixed, and if they don't do those three things I want it to show an error.

  • RELEVANCY SCORE 2.96

    DB:2.96:Super Class And Subclass mf


    While creating an instance for the subclass
    will there be any instance created for the superclass
    internally ??

    DB:2.96:Super Class And Subclass mf

    while instantiating class Z all of the base class
    constructors will be executed right....!(from A to
    Z)Yes.

    So,
    While execting the constructor of a
    of a class,instance will be created
    or not ?? No. The instance is created and then the constructor is executed to initialize the instance. 26 constructors, just one instance.

  • RELEVANCY SCORE 2.96

    DB:2.96:Why Class Keystore Is Not A Subclass Of Class Keystorespi? 93


    In JCA architecture, every engine class has a corresponding SPI class, such as Signature/SignatureSpi, or Keystore/KeystoreSpi.

    The question is why class Signature is designed to be a subclass of class SignatureSpi, while Keystore is not a subclass of class KeystoreSpi? Is there any special purpose in this implementation?

    DB:2.96:Why Class Keystore Is Not A Subclass Of Class Keystorespi? 93


    Hey-

    From what little I know (and really, it's very little), the "preferred" implementation here is what Keystore is doing. Keystore uses aggregation to provide access to the SPI-based implementation of itself, this way the user of this class never sees any part of the actual implementation (it only shows up in the protected constructor). The Signature class extends the SPI class for historical reasons, thus "exposing" the user of the class to this implementation class (through the inheritance tree), but this is not the preferred way to implement this stuff.

    I hope this made sense, please someone correct me if I'm off base here.

    Lee

  • RELEVANCY SCORE 2.95

    DB:2.95:Instantiating Member Classes Using Reflection jp


    I have checked through this forum but if the answer to this question is here I missed it.

    I am trying to find out how to invoke the appropriate instantiation / constructor call to create an instance of a member class.

    The following works finepublic class Succeeds {
    public abstract static class AbstractMember {
    }
    Succeeds(final AbstractMember am) {
    }
    public static void main(final String[] args) {
    Succeeds a = new Succeeds (new Succeeds.AbstractMember () {
    }) ;
    }
    }However I want to make the AbstractMember a real member class not a nested inner class and I want to instantiate the concrete subclass of AbstractMember in the constructor of Succeeds rather than outside the class. I tried the following:public class Fails {
    public abstract class AbstractMember {
    public class ConcreteMember extends AbstractMember {
    }
    }
    Fails(final Class? extends AbstractMember c)
    throws InstantiationException, IllegalAccessException {
    AbstractMember am = c.newInstance() ;
    }
    public static void main(final String[] args)
    throws InstantiationException, IllegalAccessException {
    Fails a = new Fails (Fails.AbstractMember.ConcreteMember.class) ;
    }
    }(Please forgive the appling treatment of exceptions, I wanted to make a small example). This compiles fine but fails at runtime with an InstantiationException I assume because the nullary constructor doesn't exist for a member class because of the need to make the connection to the containing object.

    So the question is is there a bit of reflection that allows me to achieve what I want?

    I cannot be the first person to try doing this. I am hoping it is doable otherwise I am going to have to make the design a bit yukky.

    Thanks.

    DB:2.95:Instantiating Member Classes Using Reflection jp

    On reflection (!) I think you are right and it may well be impossible to do what I was originally thinking of as the AbstractMember is abstract and so cannot be instantiated explicitly as would seem to be required to instantiate a member subclass like ConcreteMember using reflection.

    I have adjusted the design slightly so as to use interfaces rather than abstract classes and just have to suffer the lack of niceness of the original namign scheme. It all seems to work as required.

    Thanks for your help on this, it is much appreciated.

  • RELEVANCY SCORE 2.95

    DB:2.95:Core Java 31


    Q : Is a class a subclass of itself?

    Ans : Yes A class is a subclass of itself.

    Pls explain it. How it is possible?

    DB:2.95:Core Java 31

    This will answer the question

    public static boolean isThisClassIsASubclassOfItSelf(Class c){
    return c.equals(c.getSuperclass());
    }

  • RELEVANCY SCORE 2.95

    DB:2.95:Calendar &Amp; Gregoriancalendar 98


    I know that Calendar is an abstract class. We can get an instance of an Calendar by calling the getInstance() method. However, in the API for Calendar, it said
    Subclasses of Calendar interpret a Date according to the rules of a specific calendar system. The platform provides one concrete subclass of Calendar: GregorianCalendar. Future subclasses could represent the various types of lunar calendars in use in many parts of the world.

    so... is it means that
    Calendar c = Calendar.getInstance()
    is same as
    Calendar c = new GregorianCalendar();
    by default ???

    DB:2.95:Calendar &Amp; Gregoriancalendar 98

    is it means that
    Calendar c = Calendar.getInstance()
    is same as
    Calendar c = new GregorianCalendar();
    by default ?Unless your default locale and timezone are Thai related, it is close to the truth. For other locale/timezone, the method returns
    new GregorianCalendar(java.util.TimeZone defaultzone, java.util.Locale defaultlocale);

  • RELEVANCY SCORE 2.93

    DB:2.93:Writing Midi Files j1


    i've written a program which creates a sequence and adds tracks and events and everything to it, but i don't know how to then export this as a midi file. the midiFileWriter class is abstract and there doesn't seem to be any concrete subclasses. surely i dont have to write the subclass myself (which would include learning how a midi file is encoded and stuff) do i?

    any help would be much appreciated.

    DB:2.93:Writing Midi Files j1

    I need some code that does exactly what you have done, but I have no idea how to do it.
    could you send me some examples of how to create a track, add some events, etc?
    Please send it to robertozacha@arnet.com.ar
    thanks
    roberto

  • RELEVANCY SCORE 2.92

    DB:2.92:Generic Monobehaviour From Assembly pm



    Ok, i did again some tests (the last ones were ages ago). It's true that Unity can work with concrete classes, even when they are derived from a generic class. However Unity's DLL importer which looks for MonoBehaviour components seems to generally reject all classes that have a generic super class somewhere up the hierarchy. So while it's possible to actually use the class, the Editor won't recognise it as a valid component since no MonoScript subasset has been generated for that class.


    This is actually a bug in Unitys DLL importer.


    In the example case of a Monobehaviour-singleton there are two possible options based on if the singleton is generated on-the-fly or if it's a scene-based / serialized singleton:


    If you don't need serialization, it should work out of the box. The instance is created when you first access the singleton, just as expected.


    If you want to preinitialize the instance you have to create another subclass in the project itself as a dirty workaround.


    Example:


    // inside our external DLL

    public class SingletonTSelfType : MonoBehaviour where TSelfType : MonoBehaviour
    {
    private static TSelfType m_Instance = null;
    public static TSelfType Instance
    {
    get
    {
    if (m_Instance == null)
    {
    var type = typeof(TSelfType);
    m_Instance = (TSelfType)FindObjectOfType(type);
    if (m_Instance == null)
    {
    m_Instance = (new GameObject(type.Name)).AddComponentTSelfType();
    }
    DontDestroyOnLoad(m_Instance);
    }
    return m_Instance;
    }
    }
    }

    public class SomeManager : SingletonSomeManager
    {
    public string someString;
    public int someInt;
    public Transform someOtherObject;
    }



    When we import this DLL into our project, Unity won't recognise SomeManager as component. But if we add another script (SomeManagerImp.cs) to our project which contains this class:

    // inside our Unity project
    using OurDLLNamespace;

    public class SomeManagerImp : SomeManager
    {
    // empty
    }



    We can add an instance of this class to a gameobject in the scene and have our serialized instance. The singleton still works fine since this class is a subclass of the singleton.

    DB:2.92:Generic Monobehaviour From Assembly pm


    Unity can't unity-serialize the types of generic objects. It's impossible.


    I've done a few things that need types serialized, and usually I end up going with a string to represent the type (which can be selected from a drop-down if you write a custom editor / property drawer). In your case though, you might have Base : Monobehaviour and MyScript : Base, and then something stupid like BaseLogic T : object which just contains the generic functions you need. A Base would create a personal instance of a BaseLogic of its own type (MyScript or Base) and link it to itself.


    Dealing with Unity not serializing generics is always yucky, I'd recommend avoid needing generics of serialized Unity-types where possible (MonoBehaviour, ScriptableObject, whatever else).

  • RELEVANCY SCORE 2.91

    DB:2.91:Java.Lang.Reflect Question kc


    I'm beginning to explore java.lang.reflect and need some help.

    let A be an abstract class
    let C be a concrete subclass that extends A
    let L be a list that contains elements from the same concrete subclass.

    What do I need to put in for the ???? so the following statement works

    // create an array of C
    L cList = new L(C.class,48)class L {
    A a[];
    public L(Class subclass, int initialSize) {

    //create an array of sublcass

    a = new ????[initialSize]
    }

    DB:2.91:Java.Lang.Reflect Question kc

    Thanks to both of you for your replies. I eventually found the static array method for the second reply while waiting for a response, but was intrigued with the possibilities offered in the first reply.

    Thanks to you both. I learned something useful.

  • RELEVANCY SCORE 2.90

    DB:2.90:Re: Accessing Arraylist From Another Class s9


    since you can't instantiate an abstract class, this ArrayList in that class won't ever actually exist. is this other concrete class a subclass of the abstract one? have a "getList" method on the abstract class that returns it

  • RELEVANCY SCORE 2.90

    DB:2.90:Howto Avoid Specifying The Type For Every Subclass? k9


    Hi,

    I have a base-class called DynTableColumn, one subclass which further restricts the type and a bunch of subclasses of that type.

    class BaseClassE {}

    StricterBaseClassE extends ArgumentType extends BaseClassE {}

    ConcreteClass1E extends ArgumentType extends StricterBaseClassE {}
    ConcreteClass2E extends ArgumentType extends StricterBaseClassE {}
    ConcreteClass3E extends ArgumentType extends StricterBaseClassE {}
    ConcreteClass4E extends ArgumentType extends StricterBaseClassE {}Is there any way to avoid specifying E extends ArgumentType for ConcreteClass 1-4 again and again?
    After all, the type information is already set by StricterBaseClass.

    Re-thinking the question I guess I am searching for a way to de-generify concrete subclasses.
    For the example above I know the generic type is of type ArgumentType, so no further need to specify it in the class hierachy nore at construction time.

    Thank you in advance, Clemens

    DB:2.90:Howto Avoid Specifying The Type For Every Subclass? k9

    dannyyates wrote:
    Except that they're not the same thing...plus-plus.

    FWIW, if you're creating so many classes that you get annoyed by boilerplate in class definitions (not even usages) then perhaps you have an over- or poorly-engineered architecture.

  • RELEVANCY SCORE 2.89

    DB:2.89:Re: Equivalent Of Getclass() From A Static Context (Such As Main)? jc


    need to be able to create an instance of the
    subclass from within the superclassWhat do you mean?

    Generally, Class object can be gotten from:
    Class claz = ClassName.class;

    Class stringClass = String.class;In this case I don't know the name of the class. There is a static function in a superclass that needs to know what its subclass is, and be able to instantiate it. So, for example, if the superclass defines public static void main(), and the subclass simply implements some other functions, when Java executes the subclass it runs the superclass's main(). That main() needs to be able to instantiate the subclass.

    Here's what I'm doing right now:

    abstract class SuperClass
    {
    protected static String subclassName;

    public static void main(String args[])
    {
    Class subClass = Class.forName(subclassName);
    Constructor subCons = subClass.getConstructor("".getClass());

    SuperClass instance = subCons.newInstance("");
    }
    }

    class SubClass
    {
    static {
    subclassName = "SubClass"
    }
    }Is there a better way?

    DB:2.89:Re: Equivalent Of Getclass() From A Static Context (Such As Main)? jc

    Why do you want to start in the subclasses? What kind of functionality do the subclasses have?

    Perhaps you can have a completely separate class that has a main() method, and which will instantiate one of the subclasses based on an arg on the command line.

  • RELEVANCY SCORE 2.87

    DB:2.87:Overriding A Function. x3



    I don't know if your problem is so simple, but what I imagine is that you need to declare the controller class as abstract, implement the standard get function, declared as virtual, and just override it in your player subclass.


    Check the second code example here:


    http://msdn.microsoft.com/en-us/library/ebca9ah3(v=vs.80).aspx

    DB:2.87:Overriding A Function. x3


    I don't know if your problem is so simple, but what I imagine is that you need to declare the controller class as abstract, implement the standard get function, declared as virtual, and just override it in your player subclass.


    Check the second code example here:


    http://msdn.microsoft.com/en-us/library/ebca9ah3(v=vs.80).aspx

  • RELEVANCY SCORE 2.87

    DB:2.87:Mixing Concrete Classes And Ejb Interfaces s7



    This is a generic EJB question - not JBoss specific. I've posted this question in Sun's forums, but I haven't received any replies.I'm trying to define a non-ejb interface that I would like to 'overlay' or override with methods from an ejb interface. The non-ejb interface has a superset of the ejb's methods, and both interfaces share (or duplicate) some methods.What I'm trying to accomplish: I'd like to write a concrete class that implements the non-ejb interface, then be able to subclass that concrete class and implement the ejb interface. The reason I'm trying to do this is because I'm developing a standalone remote client whose base classes can optionally offload some tasks to an app server.Example:public interface foo{public void Method_A();public void Method_B();public void Method_C();public void Method_D();}public interface ejb_foo extends EJBObject{public void Method_B() throws RemoteException;public void Method_C() throws RemoteException;}public class foo_bar implements foo{public void Method_A(){...};public void Method_B(){...};public void Method_C(){...};public void Method_D(){...};}public class ejb_foo_bar extends foo_bar implements ejb_foo{}My goal with ejb_foo_bar is to have Method_A and Method_D call the concrete super class, and have Method_B and Method_C call the ejb.Is there a way I can make something like this work? I'm aware that I can just make an instance of the ejb within ejb_foo_bar then override the duplicate methods to call the ejb's methods. I'm just wondering if there is a 'cleaner' way to do it.Thanks in advance for your help!

    DB:2.87:Mixing Concrete Classes And Ejb Interfaces s7


    This is a generic EJB question - not JBoss specific. I've posted this question in Sun's forums, but I haven't received any replies.I'm trying to define a non-ejb interface that I would like to 'overlay' or override with methods from an ejb interface. The non-ejb interface has a superset of the ejb's methods, and both interfaces share (or duplicate) some methods.What I'm trying to accomplish: I'd like to write a concrete class that implements the non-ejb interface, then be able to subclass that concrete class and implement the ejb interface. The reason I'm trying to do this is because I'm developing a standalone remote client whose base classes can optionally offload some tasks to an app server.Example:public interface foo{public void Method_A();public void Method_B();public void Method_C();public void Method_D();}public interface ejb_foo extends EJBObject{public void Method_B() throws RemoteException;public void Method_C() throws RemoteException;}public class foo_bar implements foo{public void Method_A(){...};public void Method_B(){...};public void Method_C(){...};public void Method_D(){...};}public class ejb_foo_bar extends foo_bar implements ejb_foo{}My goal with ejb_foo_bar is to have Method_A and Method_D call the concrete super class, and have Method_B and Method_C call the ejb.Is there a way I can make something like this work? I'm aware that I can just make an instance of the ejb within ejb_foo_bar then override the duplicate methods to call the ejb's methods. I'm just wondering if there is a 'cleaner' way to do it.Thanks in advance for your help!

  • RELEVANCY SCORE 2.85

    DB:2.85:Abstract Class And Concrete Class am


    I can't understand why need to creat Abstract class.What's the actual purpose to creat Concrete class to overrides or implements Abstract class methods?
    Help me to understand.

    DB:2.85:Abstract Class And Concrete Class am

    I can't understand why need to creat Abstract
    class.What's the actual purpose to creat Concrete
    class to overrides or implements Abstract class
    methods?
    Help me to understand.A class that's not completely concrete cannot be instantiated (objects cannot be created).

  • RELEVANCY SCORE 2.85

    DB:2.85:Subclassing An Empty Class 8c


    Hi gurus,

    I would like to know if there is any penality involve if one subclass a concrete class but the specialized class is an empty class. If there is any penality involve like wastage of memory, how do I go about proving it?

    Thanks.

    Regards,
    Wendy.

    DB:2.85:Subclassing An Empty Class 8c

    Well, for disk memory write something with and something without the subclass and compile and compare. For RAM, you probably need to find a utility to determine exact memory usage of each process (from I don't know where), or create some really, really HUGE arrays of each type and compare the total system memory usage many times to get an average increase for running one version vs the other version (average, cause the OS will be doing diff things, and total system memory only works if you are the only one using the machine in any way.). The difference will be most noticeable if the test class is very small (like one integer data component only). I suspect the overhead is the same for a small class as a big class, but I don't know and that would be an interesting question to look at too. I'm curious to find out what you learn.... particularly if you find a useful utility.

  • RELEVANCY SCORE 2.84

    DB:2.84:Abstract Class Implements Cloneable... How? cf


    I have an abstract class that is inherited by many many subclasses. I wish to make this abstract class a cloneable.
    Most of the subclasses are using the protected fields inherited from the abstract one, they almost never add any extra field. So it would make a lot of sense to implement the clone() method at the abstract level. And not doing so would cost me a lot of time.

    But that causes me trouble, because you can't write something like this :
    public abstract class MyAbstractClass implements Cloneable {
    protected Source source; // the two fields the subclasses are satisfied with, most the time
    protected VectroTarget targets;

    public Effect clone() {
    return new Effect(source , targets); // when a subclass has extra fields, I plan to overwrite clone()
    }
    }Because you can't instantiate an abstract class, of course. Anyway, I'd rather instatiate a class of the appropriate concrete class.
    I feel there is a way to hack this. I feel there is a way to avoid having to write the same clone() method in every subclass.
    Anyone?

    Thanks.

    DB:2.84:Abstract Class Implements Cloneable... How? cf

    jverd wrote:
    bestam wrote:
    Most of the subclasses are using the protected fields inherited from the abstract one, Bad idea. Make the fields private and provide protected get/set methods.Is this a general recommendation or only in the context described by the OP?
    Because API classes don't do this in many cases. Just looked at a random one: AbstractButton.

  • RELEVANCY SCORE 2.84

    DB:2.84:Interception Of Subclass Methods 7f



    I'm having a problem with SFSB inheritence that seems very odd to me. I have an abstract class/interface which is extended by a concrete implementation. The superclass defines an abstract getEntityManager() method which returns an EntityManager that has been injected using seam managed persistence in the subclass. Now, the problem is if I access any of the methods defined in the subclass and it's interface, the EntityManager is injected and everything works fine, but if I call a method defined in the superclass/interface it does not appear to be intercepted, no injection occurs and I get a NullPointerException. I have @Intercept(InterceptionType.ALWAYS) set on all the relevent classes and I can't imagine this would be considered a feature. Can anybody tell me what's going on?

    DB:2.84:Interception Of Subclass Methods 7f


    It does seem to have fixed the problem. I'm surprised no one has run across that before.

  • RELEVANCY SCORE 2.83

    DB:2.83:(Kodo 3.4.4) Horizontal Mapping &Amp; Pc Collection jf


    Class PARENT has a collection of CHILD. This is a polymorphic collection. That is, CHILD is horizontally mapped; so that clients can subclass CHILD and introduce their own concrete classes.

    Thus, the mapping for PARENT is:

    class name="PARENT" identity-type="application"
    field name="children"
    collection element-type="CHILD"
    /collection
    extension vendor-name="kodo" key="jdbc-field-map" value="pc-collection"/extension
    extension vendor-name="kodo"
    key="jdbc-field-map/element-column"
    value="ELEMENT"
    /extension
    extension vendor-name="kodo"
    key="jdbc-field-map/ref-column.ID"
    value="PARENT_ID"
    /extension
    extension vendor-name="kodo"
    key="jdbc-field-map/table"
    value="CHILDREN"
    /extension
    /field
    ...
    /class

    I have a subclass of CHILD called TEENAGER.

    class name="TEENAGER"
    identity-type="application"
    persistence-capable-superclass="CHILD"

    ..
    /class

    When I tried to makePersistent on a PARENT with one instance of TEENAGER; I get this error:-

    Caused by: kodo.util.FatalInternalException: Object id was null for persistent instance of type TEENAGER
    at kodo.jdbc.meta.PCObjects.getDataStoreValue(PCObjects.java:40)
    at kodo.jdbc.meta.PCObjectCollectionFieldMapping.getDataStoreValue(PCObjectCollectionFieldMapping.java:43)
    at kodo.jdbc.meta.ColumnCollectionFieldMapping.update(ColumnCollectionFieldMapping.java:247)
    at kodo.jdbc.runtime.UpdateManagerImpl.update(UpdateManagerImpl.java:390)
    at kodo.jdbc.runtime.UpdateManagerImpl.flush(UpdateManagerImpl.java:143)
    at kodo.jdbc.runtime.UpdateManagerImpl.flush(UpdateManagerImpl.java:95)
    at kodo.jdbc.runtime.JDBCStoreManager.flush(JDBCStoreManager.java:614)
    ... 16 more

    What am I missing to solve the null objectid ?

    Thanks

    DB:2.83:(Kodo 3.4.4) Horizontal Mapping &Amp; Pc Collection jf

    Hi Gavin, how/where did you get hold of Kodo 3.4.4 ? I'm still using ye
    olde 3.4.1... Cheers!

    .droo.

    I fixed it! Hurray.

  • RELEVANCY SCORE 2.82

    DB:2.82:Abstract Classes mj


    why do we write abstract classes? why dont we write a concrete class instead?

    ex:

    abstract class A{
    abstract void shape();
    }

    why dont we write :

    class A{
    void shape(){
    }
    }
    and get this extended by some subclass?

    why do we need abstraction?

    DB:2.82:Abstract Classes mj

    you must re-learn object oriented programming :)

  • RELEVANCY SCORE 2.82

    DB:2.82:Should I Get This Jdofatalinternalexception? fx


    Using 2.3.4:

    abstract class A
    {
    Collection _children; // Collection of concrete A subclass instances.
    A _parent; // reference to a concrete A subclass instance.
    }

    class B extends A
    {
    // in instances of this class _children is a collection of B's and
    parent references a B
    }

    package.jdo:
    class name="A"
    field name="_children"
    collection element-type="A"/
    extension vendor-name="kodo" key="inverse" value="_parent"/
    /field
    /class
    class name="B" persistence-capable-superclass="A"/

    When I try to persist an instance of B I get the error:
    javax.jdo.JDOFatalInternalException

    at
    com.solarmetric.kodo.runtime.FieldManager.storeStringField(FieldManager.java:137)

    at
    com.solarmetric.kodo.runtime.StateManagerImpl.providedStringField(StateManagerImpl.java:1125)

    at
    au.com.oakton.monet.product.domainmodel.ProductType.jdoProvideField(ProductType.java)

    at
    com.solarmetric.kodo.runtime.StateManagerImpl.provideField(StateManagerImpl.java:1993)

    at
    com.solarmetric.kodo.runtime.StateManagerImpl.saveFields(StateManagerImpl.java:1710)

    at
    com.solarmetric.kodo.runtime.PNewState.initialize(PNewState.java:19)

    at
    com.solarmetric.kodo.runtime.StateManagerImpl.setJDOState(StateManagerImpl.java:259)

    at
    com.solarmetric.kodo.runtime.StateManagerImpl.setJDOState(StateManagerImpl.java:221)

    at
    com.solarmetric.kodo.runtime.StateManagerImpl.initialize(StateManagerImpl.java:158)

    at
    com.solarmetric.kodo.runtime.PersistenceManagerImpl.makePersistentFilter(PersistenceManagerImpl.java:985)

    at
    com.solarmetric.kodo.runtime.PersistenceManagerImpl.makePersistent(PersistenceManagerImpl.java:932)

    at
    au.com.oakton.monet.product.domainmodel.SetupData.createProductTypes(SetupData.java:772)

    at
    au.com.oakton.monet.product.domainmodel.SetupData.createProductConfiguration(SetupData.java:66)

    at
    au.com.oakton.jcore.utilities.initialisation.SetupData.main(SetupData.java:94)

    Exception in thread "main"

    Thanks,
    Tom

    DB:2.82:Should I Get This Jdofatalinternalexception? fx

    Abe White wrote:
    This is really strange, and I don't think it's related to the relations
    between your objects as you've described them. Can you reproduce this?
    Can you send us a program that demonstrates it? It looks to me like the
    JDO metadata we're storing internally is somehow out of synch with the
    object. Before you bother sending us anything, can you try recompiling and
    re-enhancing just to be safe?I'm embarrassed -- it doesn't do it anymore.

    Sorry,
    Tom

  • RELEVANCY SCORE 2.81

    DB:2.81:About Method j1


    Look at the code below and can you tell me why the code prints out:
    SuperClass Constructor Executed
    SubClass Constructor Executed
    methodA in Superclass
    methodB in Superclass//Why not prints out methodB in Subclass,since methodB in sub has been overriden
    9

    public class Superclass {
    Superclass() {
    System.out.println("SuperClass Constructor Executed");
    }

    private int methodB() {
    System.out.println("methodB in Superclass");
    return 9;
    }

    int methodA() {
    System.out.println("methodA in Superclass");
    return methodB();
    }
    }

    class Subclass extends Superclass {
    Subclass() {
    System.out.println("SubClass Constructor Executed");
    }

    public static void main(String[] args) {
    System.out.println(new Subclass().methodA());
    }
    protected int methodB() {
    System.out.println("methodB in Subclass");
    return 1;
    }
    }

    DB:2.81:About Method j1

    All instances of Subclass are instances of Superclass,
    so the answer is strictly yes....okay, fair enough.
    To make it clear: Only one object gets created. It is an instance of Subclass and is also an instance of every super class of Subclass, including both Superclass and java.lang.Object.

  • RELEVANCY SCORE 2.81

    DB:2.81:Why Doesn't This Work? fm


    My code (simplified):

    public abstract class SuperClass {
    }public class SubClass {
    }public class GenericT extends SuperClass {

    private T theClass;

    public Generic() {
    super();
    theClass = new SubClass();
    }

    }javac reports:
    Generic.java:7: incompatible types
    found : SubClass
    required: T
    theClass = new SubClass();
    ^
    1 errorWhy can't I assign a subtype of T to a variable of type T?

  • RELEVANCY SCORE 2.81

    DB:2.81:Inheritance In The Java Class Heirarchy mp


    ok two questions.

    1. in the java class heirarchy, do the subclasses inherit all of the concrete methods from the superclass, that the subclass has not overridden. Or just some of them as Sun has deemed necessary?

    2. In the situation where you have a custom class that extends another class, can you invoke all of the constructors in the superclass using the super keyword, or just some of the constructors?

    Thanks.

    DB:2.81:Inheritance In The Java Class Heirarchy mp

    Fguy wrote:
    Thanks, warnerja, that answers my question, but introduces another one, which is when I think about that, It's not clear why having a private constructor accessible by another constructor in the same class provides any advantage over just a private method,In addition to what's already been said: A c'tor is for initializing a newly created object to a valid state, and is invoked at most once per instance. A method is for performing an operation on an existing object, and can be invoked as many times as desired.

  • RELEVANCY SCORE 2.80

    DB:2.80:Re: Why Do We Require Type Casting? kj


    Hi,
    Thanks for all you views!!!!
    Now from your posts and my prior knowledge I can understand that
    there are casting which can be done in two ways either upcasting or downcasting.Regarding the downcasting I can understand that you are trying to call the members present in the concrete class(sub class),and there is a possibility that the members are present in subclass but not in the base class.So if you have the reference of generic type you can't call the methods added in the extended class.So down casting is clear ....
    If I have the sub class ie extended version reference already then why do I require to upcast..As already mentioned in posts to return the downcasting object for the samples explained then where do I require the upcasting.......
    regards
    vicky

  • RELEVANCY SCORE 2.80

    DB:2.80:Without Subclass We Don't Use Abstract Class? ad



    It Correct or Not?

    Explain correct answer?

  • RELEVANCY SCORE 2.80

    DB:2.80:Troubles With Table-Per-Class Inheritance 1j



    I'm trying to implement Hibernate's table-per-concrete class strategy using EJB3.0's TABLE_PER_CLASS inheritance and the latest CVS source code.This used to work in preview 4, but with the latest source code I don't seem to have the ability to overwrite the @Table attribute on the subclass, and it appears to automagically create a "type" attribute that shouldn't exist.My base class looks like:@Entity(access = AccessType.FIELD)@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)public abstract class BaseEntity3EntityPKType extends PK3 implements java.io.Serializable, Comparable{ @Id(generate = GeneratorType.NONE) @Column(name="ID") protected long id; @Version @Column(name="VERSION") protected long version; ...}My concrete subclass is:@Entity(access = AccessType.FIELD)@Table(name = "Groups")public class Group3 extends BaseEntity3GroupPK3{ @Column(name="NAME", nullable=false, length=50) protected String name; @Column(name="DESCRIPTION", length=50) protected String description; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name="PREFERENCE_PARENT_ID") protected Group3 preferenceParent; ...}When I do a find on Group3, the SQL looks like: select group3x0_.ID as ID, ... from BaseEntity3 group3x0_ where group3x0_.TYPE='com.portblue.model.admin.group.Group3' ...I've tried putting a @Inheritance tag on the subclass as well as on the superclass, and I get the Hibernate error: org.hibernate.AnnotationException: TABLE_PER_CLASS only allows hierarchy leaf mappingI also tried putting a union-subclass hibernate mapping in a Group3.hbm.xml file, but then I got a complaint about "duplicate mappings".Am I missing something? Thanks...- Mark

    DB:2.80:Troubles With Table-Per-Class Inheritance 1j


    seems to be a similar problem i ran into - worked fine until i used the cvs version:@Entity@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)public class DBObject implements java.io.Serializable { private long id; private Date lastChanged; private Date created;i used this base class to define fields which must be present in every class/table:@Entity@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)public class Customer extends DBObject {with the jboss-head from cvs it doesn't work. the error is:TABLE_PER_CLASS only allows hierarchy leaf mappingis there any way to get around this for now?

  • RELEVANCY SCORE 2.80

    DB:2.80:Abstract Class Costructor jf


    I came to know that even abstract classes have constructors,
    which get called when concrete subclass is instantiated.
    In order to create an instance of a class we need a constructor so if we have constructor of abstract classes why can't we create object of abstract classes?

    DB:2.80:Abstract Class Costructor jf

    @Op. You can't instantiate it since the author of the class has decided that it should be subclasses (by design) or that the class doesn't have implementation for all methods.

  • RELEVANCY SCORE 2.80

    DB:2.80:Creating A Custom Test Type In Vs 2005 Team System 7p


    I am interested in adding a new test type to VS 2005 Team System. The document "Creawteing Custom Test Types in Visual tudio 2005 Team System" gives instructions to "create a shared instance of the class TestType" and "to subclass TestTlement". What assembly are these two classes defined in?Sam

    DB:2.80:Creating A Custom Test Type In Vs 2005 Team System 7p

    Has anyone been successful in deploying the Custom Test Type Sample? I am able to build it and register the package in the experimental build, but cannot get the templates to show up in any of the dialogs ( Tools-New Test , Add-New Test, or Add-New Item). I have followed the procedures several times and ran devenv /setup on the Exp hive to no avail. Can anyone list the exact steps to register the custom test type with VS2005?Thnx in advance.

  • RELEVANCY SCORE 2.80

    DB:2.80:Base Is Serailizable, How About Subclass? kf


    Hi, Can anyone tell me if the base class implements serializable, and if you extends the base class, does your subclass have to implement serializable too? Thanks!

    DB:2.80:Base Is Serailizable, How About Subclass? kf

    No, it already does because the base class does.

  • RELEVANCY SCORE 2.80

    DB:2.80:Accessor Of The Overriding Methods f9


    Hi, if a method is a public, can the same method in the subclass be private? If yes, under what circumstance does it make sense?
    And how about the other way around: private method in the super class vs public method in the sub? The latter makes more sense to me - we "declassify" some earlier secrets...

    Thanks!

    DB:2.80:Accessor Of The Overriding Methods f9

    sure, maybe I rely on the good folks in this community too much. :-)Much too much. Waste of time when you have an accurate tool on your own computer.

    You're also relying on them being (a) good (b) correct and (c) timely. Again your compiler can beat them at that hands down.

  • RELEVANCY SCORE 2.79

    DB:2.79:Concrete Class 8c


    What is concrete class?

    DB:2.79:Concrete Class 8c

    public class Concrete implements BuildingMaterial {
    }

  • RELEVANCY SCORE 2.79

    DB:2.79:Possible Problem With Javax.Xml.Stream.Xmlinputfactory Class d1


    I think that javax.xml.stream.XMLInputFactory.newInstance(String, ClassLoader) is not behaving correctly.

    Expected Behavior:

    The first argument is name of the factory to find (ex "javax.xml.stream.XMLInputFactory"). Using this factory name go though the standard lookup procedure (ie check for a system property, check for $JAVA_HOME/lib/stax.properties, check jar META-INF/services) to determine the concrete class and return an instance loaded with the given classloader.

    Actual Behavior:

    The method assumes the first argument is the classname of the concrete XMLInputFactory subclass and tries to return an instance loaded by the given classloader.

    javax.xml.stream.XMLInputStream:
    /**
    * Create a new instance of the factory
    *
    * @param factoryId Name of the factory to find, same as
    * a property name
    * @param classLoader classLoader to use
    * @return the factory implementation
    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
    */
    public static XMLInputFactory newInstance(String factoryId,
    ClassLoader classLoader)
    throws FactoryConfigurationError {
    try {
    //do not fallback if given classloader can't find the class, throw exception
    return (XMLInputFactory) FactoryFinder.newInstance(factoryId, classLoader, false);
    } catch (FactoryFinder.ConfigurationError e) {
    throw new FactoryConfigurationError(e.getException(),
    e.getMessage());
    }
    }

    DB:2.79:Possible Problem With Javax.Xml.Stream.Xmlinputfactory Class d1

    Have not been able to find anything in the bug database.

    I am alittle worried that the StAX - 1.0.1 (http://stax.codehaus.org) has a method with the same signature that does something very different.

  • RELEVANCY SCORE 2.78

    DB:2.78:Re: Array To List kp


    Look at some of the concrete List class constructors...

  • RELEVANCY SCORE 2.78

    DB:2.78:Is A Class A Subclass Of Itself? 7z


    hello experts,

    Is a class a subclass of itself?
    every class inherits Object class. i heard somewhere that
    A class is a subclass of itself. But i dont know how is it?

    Can anyone clarify me doubt?

    Regards,
    SRI.

    DB:2.78:Is A Class A Subclass Of Itself? 7z

    kamini46 wrote:
    s a class a subclass of itself?

    We all know all the classes are sub class of Object class, but how come class can be subclass of itself? Please clarifyDon't resurrect old threads. The question has been answered. I'm locking this thread.

    Kaj

  • RELEVANCY SCORE 2.78

    DB:2.78:Re: Another Question mm


    they declared it as a type InputStream, but
    instantiated a concrete subclass of that class.
    you've heard people say "don't code to a concrete
    class"? this is what they mean

    InputStream is the most general type that can be used
    here. the code can choose to instantiate any concrete
    subclass of that type it chooses, and still work with
    it through the superclass reference. this is
    polymorphismWhich means an abstract class can be made to reference its concrete subclass.Am i right?

    DB:2.78:Re: Another Question mm

    Also google for "Liskov Substitution Principle"; for starters it can be a
    tough read but it's well worth it.

    kind regards,

    JosLiskov was discussed at some length in my interview for my current
    job. imagine my dismay when I get here and find that virtually nobody
    pays any attention to her whatsoever. argh!Well they should. The LSP is a nice litmus test whether or not a class Q
    can be an extension of a class P. I've seen so many bad counter examples.

    If someone extends a class without keeping the LSP in mind he or she
    should have his/her head nailed to the floor ;-)

    kind regards,

    Jos

  • RELEVANCY SCORE 2.78

    DB:2.78:Protected Member Access. 8a


    Hi,

    According to protected member access levels should'nt be getting a compile time error in main() saying:

    "doesNothing() has protected access in java.lang.Object"

    public class SuperClass{
    protected Object doesNothing(){
    return new Object();
    }
    }

    public class SubClass extends SuperClass{
    public static void main(String args[]){
    SuperClass sup = new SuperClass();
    SubClass sub = (SubClass) sup.doesNothing(); //line 10
    }
    }

    I am not getting that error. In LIne 10 I am trying to access A superclass protected member from a subclass using a reference which is not of the subclass type nor its further subclass type.

    Please tell me as to why am I not getting the compile time eror?

    Thanks a lot.

    DB:2.78:Protected Member Access. 8a

    But regardless, I'm glad you got your answer.

  • RELEVANCY SCORE 2.78

    DB:2.78:Generic Behavior By Partition j9


    I would like to build behavior for a domain object by partition and not
    have the object know where it is located.
    What I want to do is build a class hierarchy that would handle specific
    behavior needed by partition.
    The abstract class would handle the signatures (MyPartitionObject). The
    concrete subclasses would override the
    beahavior and would handle specific behavior required by partition. The
    concrete subclass would be would be instatiated
    upon startup of the partition. If the behavior was saving an object the
    domain class would have a template method such as:

    /*********
    DomainClass.save

    self.setUniqueNameForSave;

    MyPartitionObject.save(p_aDomainObject = self);

    MyPartitionObject.addToCache(p_aDomainObject = self);

    ********/

    The setUniqueNameForSave would not be sent to the service object since
    it is doneby the domain object.

    /************

    My client partition subclass save method would call:

    ClientSO.persistentMgr.save(aDomainObject);

    ClientSO.aCache.addToCache(aDomainObject);

    /*****************

    My server partition subclass save method would call:

    ServerSO.persistentMgr.save(aDomainObject);

    // The addToCache method would do nothing since there is not a cache
    on the server

    /*******************

    This gives us the ability to write one save method instead of
    saveForClient and saveForServer.
    The subclass of MyPartitionObject implement the correct behavior. I can
    now call save from inside a
    domain object and not have to know whether it is on the client or the
    server.

    My question is where can I put the MyPartitionObject so it can be called
    by partition ?

    Jim Hannula
    Acxiom

    -
    To unsubscribe, email 'majordomo@sageit.com' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive URL:http://pinehurst.sageit.com/listarchive/

    DB:2.78:Generic Behavior By Partition j9

    I would like to build behavior for a domain object by partition and not
    have the object know where it is located.
    What I want to do is build a class hierarchy that would handle specific
    behavior needed by partition.
    The abstract class would handle the signatures (MyPartitionObject). The
    concrete subclasses would override the
    beahavior and would handle specific behavior required by partition. The
    concrete subclass would be would be instatiated
    upon startup of the partition. If the behavior was saving an object the
    domain class would have a template method such as:

    /*********
    DomainClass.save

    self.setUniqueNameForSave;

    MyPartitionObject.save(p_aDomainObject = self);

    MyPartitionObject.addToCache(p_aDomainObject = self);

    ********/

    The setUniqueNameForSave would not be sent to the service object since
    it is doneby the domain object.

    /************

    My client partition subclass save method would call:

    ClientSO.persistentMgr.save(aDomainObject);

    ClientSO.aCache.addToCache(aDomainObject);

    /*****************

    My server partition subclass save method would call:

    ServerSO.persistentMgr.save(aDomainObject);

    // The addToCache method would do nothing since there is not a cache
    on the server

    /*******************

    This gives us the ability to write one save method instead of
    saveForClient and saveForServer.
    The subclass of MyPartitionObject implement the correct behavior. I can
    now call save from inside a
    domain object and not have to know whether it is on the client or the
    server.

    My question is where can I put the MyPartitionObject so it can be called
    by partition ?

    Jim Hannula
    Acxiom

    -
    To unsubscribe, email 'majordomo@sageit.com' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive URL:http://pinehurst.sageit.com/listarchive/

  • RELEVANCY SCORE 2.78

    DB:2.78:Enforce Static Singleton From Abstract/Interface?? 8a


    Hi,
    I'm trying to describe an interface IMyInterface which enforces all concrete subclass implementations to have a singleton "getInstance()" method whose method signature is always this "getInstance".

    So declaring the interface

    Interface IMyInterface{

    public IMyInterface getInstance();
    }
    is fine, BUT in subclasses you can't override this method with a static class method.
    ie.

    public class X implements IMyInterface
    {
    private static X instance=null;

    public static X getInstance()//ERR cannot override with static??
    {
    if( instance==null)
    instance = new X()

    return instance;
    }

    private X(){...}

    }

    ****
    I thought about using an abstract superclass but this doesn't strictly enforce subclasses to implement their own singleton class-method.
    Why can't you override the method as a class-method?...and any ideas how to achieve this enforcement of the implementation of a singleton??

    DB:2.78:Enforce Static Singleton From Abstract/Interface?? 8a

    ...so there's no way of enforcing something like a
    union pattern, so that all members of the family are
    singleton?All you can enforce with an interface is that a class which implements the interface must provide a method with a certain signature. That's all. You can't enforce anything else about that method.

  • RELEVANCY SCORE 2.78

    DB:2.78:Re: Concrete Classes 9m


    what do you want this concrete class to do?

  • RELEVANCY SCORE 2.77

    DB:2.77:Casting Objects Question p1


    class SuperClass {
    public static void staticMethod() {
    System.out.println("static SuperClass method");
    }
    public void instanceMethod() {
    System.out.println("instance SuperClass method");
    }

    }

    class SubClass extends SuperClass {

    public static void staticMethod() {
    System.out.println("static SubClass method");
    }
    public void instanceMethod() {
    System.out.println("instance SubClass method");
    }

    }

    public class TestSuperSub {
    public static void main(String[] args) {
    SuperClass superclass = new SuperClass();
    SubClass subclass= new SubClass();
    superclass.instanceMethod();
    subclass.instanceMethod();
    ((SuperClass)subclass).instanceMethod(); //--uses the instance method from SubClass
    superclass.staticMethod();
    subclass.staticMethod();
    ((SuperClass)subclass).staticMethod(); //---uses the static method from SuperClass

    }
    }

    I don't understand why calling the SubClass instance method when SubClass is cast to SuperClass runs the SubClass method but not with the static method. What is actually happening on the last line?

    RON

    DB:2.77:Casting Objects Question p1

    Absolutely!! Your help is very much appreciated.

  • RELEVANCY SCORE 2.77

    DB:2.77:Why Subclass Variable Can't Reference A Superclass Object? 8k


    Why subclass variable can't reference a superclass object?

    class A
    { //etc...
    }

    class SubClassA extends A
    { //etc...
    }

    I know subclass variable can't reference a superclass object,
    but only superclass variable can reference a subclass object.
    But I don't understand the rationale.

    Please advise. Thanks!

    DB:2.77:Why Subclass Variable Can't Reference A Superclass Object? 8k

    But if there is a method f() defined in subClassA but
    not in class A, it will yield compile error too when
    reference of type A attempts to access method f of
    object of subClassA

    class A
    { //etc...
    }

    SubClass A extends A
    {
    //etc...
    void f() {...}
    }

    A a = new SubClassA();
    a.f(); //will yield error too.Using the "instanceof" operator, you can cast to the subclass.
    public void test(){
    A a = new SubClassA();
    try{
    if(a instanceof SubClassA) ((SubClassA)a).f();
    else throw new java.lang.ClassCastException();
    }catch(java.lang.ClassCastException cce){cce.printStackTrace();}
    }

    class A{ }

    class SubClassA extends A{
    void f() {System.out.println("Please, use \"instanceof\" operator before casting!");
    }
    }

  • RELEVANCY SCORE 2.75

    DB:2.75:Extends 7x



    Does my subclass correct?

    base class: class dynamic A

    sbuclass: class B extends A

    DB:2.75:Extends 7x


    You don't need the dynamic, and it would by dynamic class A (not class dynamic A) but otherwise it's correct.

  • RELEVANCY SCORE 2.75

    DB:2.75:Final Class Vs. Final Methods In Class 37


    If I define a class as final, does every method in the class become final? I am building a library and I have classes that I do not want to allow others to subclass. I read in a book that final methods gain a little bit of speed over methods that are not declared final (but they lose the ability to become subclassed). Since this code will be running on a J2ME phone and it is networking code I need it to be as efficient as possible.

    DB:2.75:Final Class Vs. Final Methods In Class 37

    If you declare a class final, it cannot be extended, so the question of whether its methods are final is moot.

  • RELEVANCY SCORE 2.75

    DB:2.75:Subclass Multiple Classes? 8f


    How do you subclass multiple classes.I have a class that subclasses MovieClip. I added a new feature. Now its yelling that my class needs to subclass SimpleButton. Is it possible to do both? I know there both part of the display class. But how do you subclass that?thanks

    DB:2.75:Subclass Multiple Classes? 8f

    what are you doing in your movieclip subclass that uses simple buttons?

  • RELEVANCY SCORE 2.74

    DB:2.74:Downcasting A Subclass Of A Concrete Generic x7


    Hi--
    Been puzzling over this one for quite awhile, and I still can't figure it out. I'm trying to downcast a generic type to a subclass of a concrete type. Now admittedly that's messy and I'd like to refactor, but I'm still puzzled. Take the following code:

    public class Test1T {
    protected final T obj;

    public Test1(T obj) {
    this.obj = obj;
    }

    public static void main(String[] args) {
    Test1? testObj = new Test2("hello");
    System.err.println("Calling a method: " + ((Test2) testObj)).aMethod());
    }
    }

    public class Test2 extends Test1String {
    public Test2(String obj) {
    super(obj);
    }

    public String aMethod() {
    return obj;
    }
    }This fails to compile, saying that Test1capture of ? isn't convertible to Test2.

    Now suppose I change to the following:
    public class Test1T {
    protected final T obj;

    public Test1(T obj) {
    this.obj = obj;
    }

    public static void main(String[] args) {
    Test1? testObj = new Test2String("hello");
    System.err.println("Calling a method: " + ((Test2) testObj).anotherMethod());
    }
    }

    public class Test2T extends String extends Test1T {
    public Test2(T obj) {
    super(obj);
    }

    public String anotherMethod() {
    return obj;
    }
    }Here all I've done is add a parameter to the Test2 type that gives the same information available in item 1. In this case, however, it compiles and runs fine.

    Even more oddly, the following also works and does not produce any warnings:
    public class Test1T {
    protected final T obj;

    public Test1(T obj) {
    this.obj = obj;
    }

    public static void main(String[] args) {
    Test1? testObj = new Test2("hello");
    System.err.println("Calling a method: " + ((Test2) ((Test1) testObj)).anotherMethod());
    }
    }

    public class Test2 extends Test1String {
    public Test2(String obj) {
    super(obj);
    }

    public String anotherMethod() {
    return obj;
    }
    }So essentially the system is ok as long as I cast the generic type to a raw type, and then downcast to the subclass of the concrete type... but I can't do the cast directly?

    My feeling is that Java is being a little overly touchy about trying to prevent casting to a concrete type-- in the case where the type you're trying to cast to is itself not generic, shouldn't that be allowed? Or am I missing something subtle about how the generics work?

    DB:2.74:Downcasting A Subclass Of A Concrete Generic x7

    Hi Stefan--
    Thanks for pointing me to the bug report! I'd been searching but unable to find it. You're right, we were using 5.0u6 here. I tried using 5.0u12 and the problem described not occur.

    Thanks again,
    David

  • RELEVANCY SCORE 2.74

    DB:2.74:Re: Override Vs Hiding 37


    NO NO NO! what you have been saying is total garbage,
    the bigest BS i have ever seen in my whole life! to
    tell the truth, i am almost scared to death.There's nothing more annoying than an idiot who insists on butting in with incorrect information.

    a sub class can hide super class' member variables,
    it can override super class' methods. that's the
    difference, and that's it.You can also hide static methods. You should read the tutorials.

    http://java.sun.com/docs/books/tutorial/java/javaOO/override.html

    Methods a Subclass Cannot Override
    ...
    Also, a subclass cannot override methods that are declared static in the
    superclass. In other words, a subclass cannot override a class method. A
    subclass can hide a static method in the superclass by declaring a static
    method in the subclass with the same signature as the static method in the
    superclass.

    DB:2.74:Re: Override Vs Hiding 37

    and calling them using objects is the only way to
    show this "hiding"Wrong again.

    Method hiding can affect calls internal to the class where there is no class or Object specfied.

  • RELEVANCY SCORE 2.74

    DB:2.74:Concrete 17


    Hi,
    according to me,Concrete class is a class which is having all the methods has implementaion code.
    then wht is concrete method?
    please tell me

    DB:2.74:Concrete 17

    according to me,Concrete class is a class which is
    having all the methods has implementaion code.
    then wht is concrete method?A concrete method is one that's not abstract.

    If a class has one ore more abstract methods it MUST be declared abstract, but even if all methods are concrete it still CAN be declared abstract.

  • RELEVANCY SCORE 2.74

    DB:2.74:Abstract Static Methods p7


    I know it is not possible to have abstract static method.. We can have the concrete definition of static methods in abstract class and yet if we try to override this in any SubClass and try to use Polymorphism to call the method of derived class at runtime, baseclass method will be called instead.

    I wanted to ask whether or not there is a work around for this problem... My problem is that I MUST have

    1) Abstract class (consisting of abstract methods)
    and 2 classes overrrding the methods of this abstract class and then at runtime, i will call the methods of subclasses...

    Now it works OK for instance methods.. but can any one plz provide a workaround for static methods..??????

    DB:2.74:Abstract Static Methods p7

    Why would you require a static method in an abstract class?
    Do you want to achieve a similar result as in Calendar.getInstance() or DateFormat.getDateInstance() ?
    (Both classes are abstract and both have static methods; I believe this pattern is called 'Factory Method')

  • RELEVANCY SCORE 2.74

    DB:2.74:Type Param In Interface Referring To Concrete Class 7x


    I want to declare a method in an interface that takes a type parameter that represents the concrete implementing subclass. I can live with something less than that, though I would like to avoid casting as much as possible...

    Here's my attempt at a simplified (though contrived) example:

    public interface Collectable {
    CollectionCollectable collectMe();
    }
    public class StampCollection implements CollectableStamp {
    // Super-specialized collection for holding stamps
    }
    public class Stamp implements Collectable {
    public CollectionStamp collectMe() {
    return new StampCollection(this);
    }
    }This doesn't work because StampCollection is deemed to be incompatible with CollectionCollectable. I'm assuming this is because the type parameter for the interface that StampCollection implements is Stamp, which is more specific than Collectable. Is that right? What are my options for fixing this (with minimal casting).

    DB:2.74:Type Param In Interface Referring To Concrete Class 7x

    Thanks for your help, everybody. I think I now understand a bit better why one would do such a thing. I basically implemented brucechapman's suggestion, and it's working great!

  • RELEVANCY SCORE 2.74

    DB:2.74:Message From Subclass 1m


    How can I notify a main class from within a subclass...?
    I tried with throwing an exception, but is that possible?

    DB:2.74:Message From Subclass 1m

    You mean this?

    class Main{
    new Sub().takesALongTime();

    private void subIsDone(){
    }

    class sub{
    private void takesALongTime(){
    // this takes a long time
    Main.this.subIsDone();

    }
    }
    }

  • RELEVANCY SCORE 2.73

    DB:2.73:Classcastexception When Casting Array From Subclass To Super Class fp


    I am getting ClassCastException with trying to do the following:

    A SuperClass which cannot be changed.
    A SubClass which extends SuperClass.

    class SomeOtherClass {
    public SubClass[] getSubArray() {
    SuperClass[] superArray = this.getSuperArray();
    SubClass[] subArray = new SubClass[superArray.length];
    for(int i = 0; i superArray.length; i++) {
    SuperClass superObj = new SubClass();
    superObj = superArray;
    subArray[i] = (SubClass) superObj;
    }
    }

    }

    A ClassCastException is thrown at subArray[i] = (SubClass) superObj; Any other way of doing casting of array between Super and Sub Class? Thanks.

  • RELEVANCY SCORE 2.73

    DB:2.73:Datacontractserializer Doesnt Seem To Work With Subclasses kz


    Editing the original post. I narrowed this down to the fact that if a subclass does not have any members marked [DataMember], then it won't serialize any members, not even those of its base class. Sounds like a bug.
    [DataContract]
    [KnownType(typeof(Subclass))]

    public class
    Base
    {
    [DataMember]

    public int Property1 {
    get; set; }
    }

    [DataContract]

    public class
    Subclass : Base
    {
    [DataMember]

    public int Property2 {
    get; set; }
    }

    public class
    Test
    {

    public void DoIt()
    {

    Subclass b1 = new
    Subclass() { Property1 = 1, Property2 = 2 };

    DataContractSerializer serializer =
    new DataContractSerializer(typeof(Base));

    MemoryStream ms = new
    MemoryStream();
    serializer.WriteObject(ms, b1);

    ms.Seek(0,
    SeekOrigin.Begin);

    Subclass b2 = (Subclass)serializer.ReadObject(ms);

    Debug.WriteLine(b2.Property1);

    Debug.WriteLine(b2.Property2);
    }
    }
    The code above works properly. However, if you remove the [DataMember] from Property2 in the subclass, then Property1 will not be serialized at all in Subclass.

    DB:2.73:Datacontractserializer Doesnt Seem To Work With Subclasses kz

    Editing the original post. I narrowed this down to the fact that if a subclass does not have any members marked [DataMember], then it won't serialize any members, not even those of its base class. Sounds like a bug.
    [DataContract]
    [KnownType(typeof(Subclass))]

    public class
    Base
    {
    [DataMember]

    public int Property1 {
    get; set; }
    }

    [DataContract]

    public class
    Subclass : Base
    {
    [DataMember]

    public int Property2 {
    get; set; }
    }

    public class
    Test
    {

    public void DoIt()
    {

    Subclass b1 = new
    Subclass() { Property1 = 1, Property2 = 2 };

    DataContractSerializer serializer =
    new DataContractSerializer(typeof(Base));

    MemoryStream ms = new
    MemoryStream();
    serializer.WriteObject(ms, b1);

    ms.Seek(0,
    SeekOrigin.Begin);

    Subclass b2 = (Subclass)serializer.ReadObject(ms);

    Debug.WriteLine(b2.Property1);

    Debug.WriteLine(b2.Property2);
    }
    }
    The code above works properly. However, if you remove the [DataMember] from Property2 in the subclass, then Property1 will not be serialized at all in Subclass.

  • RELEVANCY SCORE 2.73

    DB:2.73:Re: String Class pm


    paulcw wrote:
    Even if it were valid for a superclass A to be immutable with a subclass B that's mutable except that the aspects of B that derive from A are immutable, I'd argue that you're making a royal mess with it that will lead to confusion and bugs in the future.Oh, heck yes. I'm not saying it's good programming practice, I'm just exploring the definition of immutable. And all analogies aside (even though I haven't seen a relevant one yet), I haven't seen a concrete example of why A isn't immutable in the above situation.

    DB:2.73:Re: String Class pm

    endasil wrote:
    public class A {
    private final int foo;
    public A ( int foo) {
    this.foo= foo;
    }

    public final int getFoo() {
    return foo;
    }

    public final boolean equals(Object other) {
    if ( other instanceof A ) {
    return foo == ((A)other).foo;
    }
    return false;
    }
    //similarly for hashCode, and any other inherited members
    }

    public class B extends A {
    private int bar;
    public B (int foo, int bar) {
    super(foo);
    this.bar = bar;
    }
    public void setBar(int bar) {
    this.bar = bar;
    }
    public int getBar() {
    return bar;
    }I do not understand the purpose of that code;
    you end up being able to have two instances of type B
    that are equal because they have the same value for foo
    yet they may very well have different values for bar.
    What is the purpose of bar? If there is no purpose, why is it there?

    Would it not be much more maintainable if B were to encapsulate A, maybe both implement a common interface.
    If you want B.equals() to to reflect A.equals() of the encapsulated As
    you are free to implement that
    and there is an obvious place to provide useful comments on this decision in the implementation.

  • RELEVANCY SCORE 2.72

    DB:2.72:Concrete Authentication With Nt In Java Programs j7


    I'm looking for some class to implement NT authentication in my java app. after searching in JAAS technology, I'm looking for concrete class, with simple interface.
    Thanks a Lot

    DB:2.72:Concrete Authentication With Nt In Java Programs j7

    I found recently that : http://jcifs.samba.org/
    Just to answer my own question ;-))

  • RELEVANCY SCORE 2.71

    DB:2.71:Paint Interface Vs Color 73


    Does anyone know why Sun implemented JComponent methods of setColor/setBackground using the concrete class of java.awt.Color rather than java.awt.Paint. It seems in order to do something as simple as set a GradientPaint or a TexturedPaint as the background you need to go through some loops (subclass and override paintComponent)? Has anyone come across a nicer way of applying a Paint to a component without subclassing?

    DB:2.71:Paint Interface Vs Color 73

    I am not really looking for a new look and feel or to change the theme. I have a simple title bar for a form in my application and I just wanted to see if there was a way to apply a gradient paint to the title bar without creating a custom component, but i see now that it is not as straight forward as you would think it should be. Thanks for your input.

  • RELEVANCY SCORE 2.71

    DB:2.71:Re: Accessing Superclass Methods c9


    I see it differently

    In the universe of enumerated items a NamedIcon
    subclass specializes in icons, a NamedMusicsubclass
    specializes in audio files, a NamedDouble subclass
    specializes in double precision values, get the
    picture ?Yes, but that isn't what you're doing. You'resaying
    a NamedIcon specializes a NamedAnything.NamedElement
    should be an interface or a mix-in (not available in
    Java), but not the base class.Why NOT a base class? A base class guarantees
    All namedAnythings have a name.
    All namedAnythings are able to compare themselves with
    other members of the same concrete subclass
    All namedAnythings are able to make arrays of the
    concrete subclass and grow or shrink the arrays
    All namedAnythings are able to read their data from a
    stream and write their data to a streamAll of which can be described by an interface. A base class implies that all sub-classes are specialized kinds of the base class. A NamedIcon isn't a specialized kind of NamedElement. It's a specialized kind of Icon. If Java had multiple inheritance of implementation you could use a mix-in to share behavior. Instead we use interfaces and delegation.

    Moreover, when I go to sort the arrays created by the
    concrete subclasses, I only need one sorting
    algorithm. Imagine sorting Icons by their thumbnails
    and getting a list of names !But if you use a sort criteria specified in NamedElement, you won't be sorting Icons by their thumbnails. You'll be sorting by their names.

    or getting a list of
    icons matching a single name. Or if you don't like
    thumbnails, how about characterizations of
    fingerprints ? The possibilities are endless.And can be accomplised with interfaces in a way that more Java (and OO) programmers will more easily understand.

    DB:2.71:Re: Accessing Superclass Methods c9

    Inheritance based on functional relationships is
    almost always wrong.I respect your opinions. How is it wrong in this
    instance ?I couldn't say. This subthread was started by you presenting a list of aspects for a problem. I noted that that specific list represented functional aspects only.

    It could be simply that your list was an incomplete representation of your system.

  • RELEVANCY SCORE 2.71

    DB:2.71:Problems With Inheritance In Unity C# Scripts c8



    There is no sub-classing, so there is no inheritance...if you want one class to inherit variables and methods of another class, you need to make that class the sub-class of the other class...


    Instead of

    public class Subclass : Monobehaviour {}



    you write:

    public class Subclass : Superclass {}

    DB:2.71:Problems With Inheritance In Unity C# Scripts c8


    I feared that was the case. I'll just have to create a main class to house the menus for my game and use subclasses to actually show the other menus or something.


    Anyway, thanks Philipp.

  • RELEVANCY SCORE 2.71

    DB:2.71:How To Map Sub Sub Class With Tpt sp


    I had a base abstract class called Party. There are four derived concrete classes (Company, Person, Department, Position). There is a property called PartyType in the base class which is used as a discriminator. My configurations have lines
    like
    MapDepartment(d = d.Requires(PartyType).HasValue(Department).ToTable(Departments);
    All is good.
    Now I want to add a subclass of Person called Employee. How to map? I've tried
    MapEmployee(e = e.Requires(PartyType).HasValue(Employee).ToTable(Employees);
    but this gives me a runtime error of
    (43,10) : error 3032: Problem in mapping fragments starting at lines 43, 84:EntityTypes WOL.EFData.Person, WOL.EFData.Employee are being mapped to the same rows in table People. Mapping conditions can be used to distinguish the rows that these types are
    mapped to.
    How do I map this?Paul Linton

    DB:2.71:How To Map Sub Sub Class With Tpt sp

    Hi PaulLinton,
    Welcome to MSDN Forum.
    HasValue method doesn't contain an inputparameter. So the mapping statement will not work. Based on this issue, if every entities' PartyType value is fixed, I suggest you to set the value in the constructor of the entity. Please refer to the code below.
    namespace ConsoleApplication38
    {
    class Program
    {
    static void Main(string[] args)
    {
    using (testContext context = new testContext())
    {
    context.Database.Create();
    }
    }
    }

    abstract class Party
    {
    public int id { get; set; }
    public string partyType { get; set; }
    }

    class Person:Party
    {
    public Person()
    {
    partyType = Person;
    }
    public string name { get; set; }
    }

    class Department : Party
    {
    public Department()
    {
    partyType = Department;
    }
    public string name { get; set; }
    }

    class Employee : Person
    {
    decimal salary { get; set; }
    public Employee()
    {
    partyType = Employee;
    }
    }

    class testContext : DbContext
    {
    public DbSetParty partySet { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
    modelBuilder.EntityParty().ToTable(Parties);
    modelBuilder.EntityPerson().ToTable(People);
    modelBuilder.EntityDepartment().ToTable(Departments);
    modelBuilder.EntityEmployee().ToTable(Employees);
    }
    }
    }

    Best RegardsAllen Li [MSFT]
    MSDN Community Support | Feedback to us

  • RELEVANCY SCORE 2.70

    DB:2.70:Enum And Polymorphism Don't Mix? d3


    I am not that comfortable with Java's enum types, so please allow me to ask the following:
    I am trying to model a restaraunt. The "Restaraunt" class will be abstract. Concrete classes like "Wendys", "BurgerKing", etc. will extend it. One abstract method in the Restaraunt class needs to be: getMenu(). And, the "getMenu()" method returns an enumeration of the items on the menu. Of course, each concrete subclass will have a unique Menu enum.

    This seems a very logical model.
    Menus should be enum.
    Having a menu is behaviour common to all restaraunts.
    The actual menu contents are specific to a subclass.
    This is begging for a polymorphic solution, yet I don't think the properties of enum types could allow for it?

    DB:2.70:Enum And Polymorphism Don't Mix? d3

    paulcw wrote:
    Anyway, all Enums extend java.lang.Enum, so they can't extend anything else.

    But enums can implement an interface, I believe. I think it would be poor design to have a "Food" interface and then have your menu be an enum implementing Food, but you could do it.wow. That is great. I did not realize an enum could implement an Interface. That sounds like an interesting path to explore. However, based on these comments, I think the behavior I want might best be served by an ImmutableSet. I have some re-design to do. Thanks for the advice.

  • RELEVANCY SCORE 2.70

    DB:2.70:Class Xxx Does Not Implement Key Field Helper Methods 1f



    Moving from 2.2.6 to 2.3.0, we're getting the following
    exception on a class hierarchy mapped to a single table:
    'javax.jdo.JDOFatalInternalException: Abstract class
    com.commercehub.core.domain.Action does not implement key field
    helper methods'. It happens when attempting to load a concrete
    subclass from the data store.

    This hierarchy was causing us trouble with 2.2.6 in a servlet
    container, but that's a known bug and we've been using the patch
    you provided to work around it.

    javax.jdo.JDOFatalInternalException: Abstract class
    com.commercehub.core.domain.Action does not implement key field
    helper methods
    at
    javax.jdo.spi.JDOImplHelper.copyKeyFieldsFromObjectId(JDOImplHelper.java:231)
    at
    com.solarmetric.kodo.util.ObjectIds.toPKValues(Unknown Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager.loadByPK(Unknown
    Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager.initialize(Unknown
    Source)
    at
    com.solarmetric.kodo.runtime.StateManagerImpl.loadInitialState(Unknown
    Source)
    at
    com.solarmetric.kodo.runtime.PersistenceManagerImpl.getObjectByIdFilter(Unknown
    Source)
    at
    com.solarmetric.kodo.runtime.PersistenceManagerImpl.getObjectById(Unknown
    Source)
    at
    com.solarmetric.kodo.impl.jdbc.ormapping.OneToOneMapping.load(Unknown
    Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager.load(Unknown
    Source)
    at
    com.solarmetric.kodo.runtime.StateManagerImpl.loadField(Unknown
    Source)
    at
    com.solarmetric.kodo.runtime.StateManagerImpl.isLoaded(Unknown
    Source)
    at
    com.commercehub.core.domain.SQTransition.jdoGetaction(SQTransition.java)
    ....

    --
    Alex Albu

    --
    Commerce Technologies, Inc.
    21 Corporate Drive
    Clifton Park, NY 12065

    DB:2.70:Class Xxx Does Not Implement Key Field Helper Methods 1f

    This bug has been fixed in our final 2.3 release, which will be available
    Real Soon Now.

  • RELEVANCY SCORE 2.70

    DB:2.70:Inheritance And Interface Invocation Query sp


    interface IProduct{
    void getProductName();
    }

    abstract class Option implements Product{
    void exercisePrice();
    void premiumPaid();
    }

    class Option1 extends Option{

    // Implement all abstract methods defined in Option and IProduct.
    }

    class Option2 extends Option{

    // Implement all abstract methods defined in Option and IProduct.
    }

    class Trade{

    public Trade(IProduct p){

    p.getProductName() // I can only get this method behaviour.

    // My Query
    // I also need to invoke the methods exercisePrice() and premiumPaid() defined in Option1 and Option2

    // If I use instanceof,the code will get cluttered and ugly.

    if p instanceof Option1
    Option1 op1 = ((Option1) p);
    op1.exercisePrice();
    ....

    if p instanceof Option2
    .....

    if p instanceof OptionN
    ....
    }

    }

    class TestHarness{

    public static void main(String args[]){

    // Create an option
    Option1 option1 = new Option1();

    // Trade in the product
    Trade trade = new Trade(option1);

    Query:

    The Trade constructor defines IProduct.
    IProduct can be a concrete Bond,Option,CDS,IRS etc.

    How do I get the methods defined in subclasses Option1 and Option2 or for any concrete subclass of IProduct?
    Is there a way of dynamically invoking the methods of the object created?

    Or do I need to change the design.

    }

    }

    DB:2.70:Inheritance And Interface Invocation Query sp

    It looks to me like you're violating the Liskov Substitution Principle.

    "The LSP says that the users of base classes should not have to do anything special in order to use derivatives."
    - R. MartinThis also violates the Open/Closed principle, because whenever you add a new Option concrete class, you're going to have to update your Trade class (it's not "closed to modification" when the environment around it changes).

    The "fix" is just that its not a good idea to force the polymorphism by using instanceof. You should either:
    1. Get rid of the IProduct interface completely and treat each product type separately.
    2. Reconsider your base class (in this case, IProduct) to see if it really can contain additional behavior applicable to all products.

    The previous post about the visitor pattern is interesting, but I don't see how it applies to this example (perhaps some more light could be shed there by the poster).

  • RELEVANCY SCORE 2.70

    DB:2.70:Super() And Subclass zz


    Does the code have the desired effect if I specify the parameters in the super() statement of this subclass?
    public class FilmContainer extends HashMap implements Serializable {

    public FilmContainer() {
    super(151, 0.6f);
    }
    }

    DB:2.70:Super() And Subclass zz


    Actually I think you might be hard-pressed to find
    any justification for subclassing HashMap.Agreed. All you have to do now is travel back in time and tell that to the person that is just about to write the java.util.Properties class.

  • RELEVANCY SCORE 2.70

    DB:2.70:Re: Why Does This Abstract Class And Method Work Without Implement It? zf


    molavec wrote:
    hi,

    I have seen many times that in some examples that there are objects made from abstract classes directly. \No, you haven't. And if you did, that code won't compile.

    Perhaps you saw an anonymous inner class, which is an unnamed class that extends some other class or implements some interface, and provides implementations for all abstract methods.

    public interface Runnable() {
    public void run();
    }

    public class MyClass {
    void foo() {
    Runnable r = new Runnable() {
    public void run() {
    // do stuff
    }
    };
    }Or perhaps they were just calling static methods, which don't require an instance of the class.

    //CONFLICT LINES
    ServerSocketChannel ssc = ServerSocketChannel.open(); //--I have never thought do that!! Anyway, how it is static method may work.
    ssc.socket().bind (new InetSocketAddress (netPort)); //--but here, this method (socket) is abstract. WHY RETURN A SOCKET???????? this mehod should be empty by default.socket() is abstract, but ServerSocketChannel.open() returns a concrete implementation/subclass of ServerSocketChannel. So ssc points to an instance of a concrete class, which has implemented socket().

    Also, I read that the abstract classes can't have static methods. Is it true???No, that's false. You could have tested that very easily yourself be creating an abstract class and giving it a static method. Or by noticing that ServerSocketChannel is abstract but yet clearly has a static method.

    Edited by: jverd on Dec 18, 2009 1:15 PM

    DB:2.70:Re: Why Does This Abstract Class And Method Work Without Implement It? zf

    That's not a reason why SocketChannel is abstract and has abstract methods. That's just a statement that it doesn't have bind(), shutdown(), or socket-option methods at all.

  • RELEVANCY SCORE 2.69

    DB:2.69:Simple Subclass Question s7


    I may have misunderstood but how should I decide to use derive or subclass

    public class Class2 extends Class1
    or
    class Class2 : public Class1

    DB:2.69:Simple Subclass Question s7

    Dalai wrote:

    ok thanks but my point was

    what's the difference between extend and derive?

    The former doesn't apply to the C programming language, while the latter does.

    Igor Tandetnik

  • RELEVANCY SCORE 2.69

    DB:2.69:C# Inheritance And Override ds



    using System;
    using System.Collections.Generic;
    using System.Text;

    class BaseClass
    {
    public virtual void method()
    { Console.WriteLine(BaseClass method); }
    }

    class SubClass : BaseClass
    {
    public override void method()
    { Console.WriteLine(SubClass method); }

    public void someMethod()
    { Console.WriteLine(); }

    static void Main(string[] args)
    {
    BaseClass var = new SubClass();

    var.method();
    var.someMethod();
    }
    }

    DB:2.69:C# Inheritance And Override ds

    Hi rassuls,

    So how is it going now with our friends' suggestions?
    We are looking forward to hearing from you.

    Have a nice day,Leo Liu [MSFT]
    MSDN Community Support | Feedback to us

  • RELEVANCY SCORE 2.69

    DB:2.69:'Inheritance' Query. z7


    I have a question regarding inheritance.

    1)'All java classes inherit from Object'.

    So if I define a class called Dog,this class indirectly inherits
    from class Object.

    This is done 'implicitly' by the compiler.

    class Dog extends Object{

    }Am I right in Point (1)?.

    2) Now lets assume that I have an interface called 'Mammal' and
    a concrete subclass called 'Dog'.

    interface Mammal{

    void sound();
    }

    class Dog implements Mammal{

    void sound(){
    System.out.println("Woof");
    }
    }

    Now,my question is:

    Does interface Mammal also extend 'Object' implicitly?


    interface Mammal extends Object {
    void sound();
    }
    If all objects indirectly inherit from class Object,
    then,how can an Interface extend a class?

    Am i wrong in my analysis?

    DB:2.69:'Inheritance' Query. z7

    Ah,thats exactly what I was thinking.
    If I instantiate the Dog class, then Dog is of type
    'Dog','Mammal' and 'Object'. Even though Dog
    implements Mammal, what the compiler
    implicitly does is:As a sidenote: you can verify that by using the javap tool in your $JAVA_HOME/bin/.
    Syntax: javap [CLASSNAME] (at least for such matters)

  • RELEVANCY SCORE 2.69

    DB:2.69:Issue With Designer Not Recognizing Concrete Overridden Method Returns sj


    I am currently building an applicationframework. There is a base form and a strip builder form that inherits from it to build tool, menu and status strips as needed. A concrete formthen inheritsfrom the strip builder form. This architecture uses MVP and the presenters are "set" in an overridden "hook" method as follows: private AbstractPresenter _presenterDelegate;public FW_BaseForm(){HookBeforeInitialize();InitializeComponent();HookAfterInitialize();} protected virtual void HookBeforeInitialize(){SetPresenter(GetConcretePresenter());}// Had to use a methods here instead of a property because // the form kept initializing my public property to null in "InitializeComponent()"public virtual void SetPresenter(AbstractPresenter pPresenter){_presenterDelegate = pPresenter;}public AbstractPresenter GetPresenter() { return _presenterDelegate; }// null return here was a problem as well so I tried a "dummy"protected virtual AbstractPresenter GetConcretePresenter(){return new DummyPresenter();}The architecture also uses 2 interfaces ( and their subclass interfaces) IViewToPresenter and IPresenterToView to communicate back and forth to/from the presenter and the view. The toolstrip form from above, implements an interface that inherits from IViewToPresenter top "get" the information from the presenter on how to build the tool/menu/status strips. Each inheriting interface also defines a property to cast the form at that level to the inheriting interface as follows: public interface IV2P_GetToolStrips : IViewToPresenter{ToolStripDescriptor GetToolStrip();MenuStripDescriptor GetMenuStrip();StatusStripDescriptor GetStatusStrip();IV2P_GetToolStrips IV2P_GetToolStrips { get;}}// the tool strip form implements the interface as follows: (only 1 method and the property are shown for brevity)#region IV2P_GetToolStrips Members public ToolStripDescriptor GetToolStrip(){// call the presenterreturn IV2P_GetToolStrips.GetToolStrip();} public IV2P_GetToolStrips IV2P_GetToolStrips { get { return ((IV2P_GetToolStrips)GetPresenter()); } } // the concrete class overrides the "GetConcretePresenter()" method:protected override AbstractPresenter GetConcretePresenter(){return new CustomerOrderManagementPresenter();}// this is the abstract presenter that implements "IV2P_GetToolStrips"public class AbstractPresenterWithToolStrips : AbstractPresenter,IV2P_GetToolStrips{public AbstractPresenterWithToolStrips() { } #region IV2P_GetToolStrips Members public virtual ToolStripDescriptor GetToolStrip(){return null;}#endregion// the only concrete code for the "CustomerOrderManagementForm" test is: public partial class CustomerOrderManagementForm : FW_BaseFormWithToolStrips{public CustomerOrderManagementForm(){InitializeComponent();HookAfterInitialize();}protected override AbstractPresenter GetConcretePresenter(){return new CustomerOrderManagementPresenter();}}The designer chokes on trying to cast the "DummyPresenter" to the interface "IV2P_GetToolStrips" which means that it is not processing the overridden method and getting the concrete instance of the "CustomerOrderManagementPresenter" . Does anyone have a work aroundfor this? The application runs and works great, but it's going to be impossible to use the framework if the designer cannot recognize overridden template methods that load concrete objects at run time.Any and all help/suggestions would be greatly appreciated.

    DB:2.69:Issue With Designer Not Recognizing Concrete Overridden Method Returns sj

    Bill,The reason for this is due to the architecture of the Windows Forms designer. The designer doesn't actuallycreate an instance of theform you are designing, but rather its base class, which in your case, is BaseFormWithToolStrips.So when GetConcretePresenter is called, BaseFormWithToolStrips.GetConcretePresenter is called, not CustomerOrderManagementPresenter.GetConcretePresenter.For more information see the following blog post: http://www.urbanpotato.net/default.aspx/document/1772To get around this there is a couple of ways:1. Don't use the designer (obviously not ideal)2. Derive another class from CustomerOrderManagementPresenter and design that instead. This will cause the correct presenter to be created and returned.3. Using Type descriptors and a custom designer, implement a class that stands in for CustomerOrderManagementForm that returns the correct presenter, for more details on this see: http://www.urbanpotato.net/default.aspx/document/2001HTHDavid

  • RELEVANCY SCORE 2.69

    DB:2.69:Help(About Class Overriding) xj


    Consider a subclass that has a method that overrides a method with the same prototype in its superclass.Now,suppose you have an object whose class is the subclass. Can you figure out a way to call the superclass method on that object without having to go through the subclass method of the same name?

    DB:2.69:Help(About Class Overriding) xj

    but that method should not be a static one?
    if I want to quote a non-static method,how can I do it?

  • RELEVANCY SCORE 2.68

    DB:2.68:Subclass Instance Not Created During Runtime d8



    Hi Experts,

    For an existing standard class a subclass was created and during runtime the me object reference points to the subclass name there by allowing the subclass additional/custom methods to be triggered.

    We have done service pack upgrade in the system and during runtime I find the subclass does not exist in the me object reference due to which the custom code in the subclass is not being called.

    How do I fix the above issue so that and subclass instance is created by the superclass during runtime?

    DB:2.68:Subclass Instance Not Created During Runtime d8


    Hello Srinivas,

    I had put a breakpoint to debug in the subclass which was being invoked.

    In the new system where the service pack has been applied I have put breakpoint in the same method but the subclass method is not being called.

    The superclass method is being called. I'm sure after facing this problem(and solving it, of course) you'll have a better understanding of the 'polymorphic' behaviour of objects

    if the subclass inherits superclass the instance will be created automatically?

    NO!!!

    You must understand none of us has a crystal ball where we can gaze find out the solution. If you want valuable responses please provide as much info as possible.

    BR,

    Suhas

  • RELEVANCY SCORE 2.68

    DB:2.68:Re: Interface, Generic, Subclass - A Design Question 98


    maxim.veksler wrote:
    Hello everyone,

    Assume the following :

    public class A { }

    public class B extends A { }
    public class C extends A { }Now I have interface and base impl
    public interface IFacade {
    public void method(A a);
    }

    public class FacadeBaseImpl implements IFacade {
    public void method(A a) {
    return;
    }Further down I have a concrete classes that know how to deal with B, C:
    public class FacadeBImpl extends FacadeBaseImpl {
    ... here I would like to implement method in such a way that I would be able to pass to it only B and subclasses of B.You'll can add a method that takes a B

    public class FacadeBaseImpl implements IFacade {
    public void method(A a) {
    return;
    }
    public void method(B b) {
    return;
    }

    DB:2.68:Re: Interface, Generic, Subclass - A Design Question 98

    Isn't this a violation of the Liskov Substitution Principle? I would think that if B and C can't be treated just like A, they shouldn't extend from it.

  • RELEVANCY SCORE 2.67

    DB:2.67:Subclass Call 8d


    Hi,
    Could any one explain the behaviour of sub class mentioned below....
    Hope the second case must call subclass but it is calling base class....
    Can any one help...

    import test.Subclass;

    /*
    * Main_1.java
    *
    * Created on August 13, 2003, 7:21 PM
    */

    /**
    *
    *
    */
    public class Base {

    /** Creates a new instance of Main_1 */
    public Base() {
    }

    public void test(Base b)
    {
    System.out.println("Exceuted base ");
    }

    public void basic(Base base)
    {
    base.test(base);
    base.test((Subclass)base);
    ((Subclass)base).test((Subclass)base);
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    Base base=new Subclass();
    base.basic(base);

    }

    }

    package test;

    /*
    * Subclassf.java
    *
    * Created on August 13, 2003, 7:24 PM
    */

    public class Subclass extends Base
    {

    public Subclass()
    {
    }

    public void test(Subclass b)
    {
    System.out.println("Exceuted subclass ");
    }

    }

    Output:

    Exceuted base
    Exceuted base /////--------------expected sub class
    Exceuted subclass

    DB:2.67:Subclass Call 8d

    In fact your Subclass.test does not override,true

    but does hide the Base.test class.false

    The method is not hidden, it is overloaded (as I said in a previous post)

  • RELEVANCY SCORE 2.67

    DB:2.67:Own Subclass zk


    CAN A CLASS BE IT'S OWN SUBCLASS?
    IF YES HOW?PLEASE GIVE ONE EXAMPLE.
    THANKS IN ADVANCE.

    DB:2.67:Own Subclass zk

    CAN A CLASS BE IT'S OWN SUBCLASS?STOP BLOODY SHOUTING!!!!!!

  • RELEVANCY SCORE 2.67

    DB:2.67:When Is A Class A Subclass kk


    I have been asked the question, is an unchecked exception a subclass of Exception. I think yes, because an unchecked exception is a subclass of RuntimeException, which is in turn a subclass of Exception.

    Therefore, an unchecked exception is a subclass of Exception, albeit an indirect subclass.

    Can anyone provide an authorative answer?

    Thanks

    DB:2.67:When Is A Class A Subclass kk

    Errors are unchecked, but does that make them a
    unchecked exceptions or unchecked errors?

    Well apparently the JLS says exception.Right.

    And note that exception != Exception. :-)

  • RELEVANCY SCORE 2.67

    DB:2.67:Re: Strict Subclasses?!? A Class Can Be A Subclass Of Its Self! p3


    How can class A be a subclass of its self?That's rubbish! A certainly isn't subclass of itself.

    DB:2.67:Re: Strict Subclasses?!? A Class Can Be A Subclass Of Its Self! p3

    izzy bizzy frizzy sloth
    walked along 'is onetime troth
    shedd'n wooly strangled cloth
    wait'n fer a moth

    When 'e ate to his content
    then went back to 'is tent
    fell asleep upon 'is bent
    bed 'is brudder lent

    And at dawn he didst awake
    'ad 'is pudds an tea an cake
    an an omlette fer 'elths sake
    e'en fed 'is snake

    Den a t'wone 'e didst return
    to 'is troth and wouldst discern
    dat 'he still 'ad much ta learn
    a 'bout mak'n broth

    ~BillDat's all I can say!

  • RELEVANCY SCORE 2.67

    DB:2.67:Question Regd Inheritance And Constructors. zc


    Hi,

    I have a question regarding inheritance and constructors

    "Constructors are mechanisms to initialize an object."

    If a subclass extends a superclass,
    the subclass then invokes the super class's constructor,(ie by saying super()),
    and then the subclass is instantiated.

    Now which object is initialised? The subclass object or the super class?

    class Parent{

    }

    class Derived extends Parent{

    Derived(){

    super();

    }

    }

    class Test{
    public static void main(String args[]){

    new Derived();
    }

    }

    DB:2.67:Question Regd Inheritance And Constructors. zc

    so in short only the object instantiated in initialized and that is the subclass.

  • RELEVANCY SCORE 2.66

    DB:2.66:Abstract Class x9


    Hi -- I have a question in Abstract Class.

    I have abstract class X with following methods
    public X{
    abstract doThis();

    concrete method exposedToOutsideWorld(){
    doThat();
    doThis();
    }

    concrete method doThat();
    }

    then I have the concrete impl
    public class Y extends X{
    //provide concrete impl for doThis()
    doThis(){
    // Blah...
    }
    }

    When Z calls new Y().exposedToOutsideWorld() -- Does doThat() gets
    executed?????

    I am runnning into a situation where it is not.
    What am i missing...

    DB:2.66:Abstract Class x9

    yeah, i'd suggest it would be called but your example doesn't give it any implementation.

  • RELEVANCY SCORE 2.66

    DB:2.66:Subclassing Picture Control In Vs 2005 ka


    Hello,I am trying to subclass Picture Control (VS 2005) in order to be able to handle the right and left mouse click events over this control.Can this be done by using a Custom Control of the form editor toolbox, and defining its Class property? Does anyone have any sample where I can understand how to do this ?Thanks in advance,David.

  • RELEVANCY SCORE 2.66

    DB:2.66:Re: A Question.... d7


    I have interpreted the keyword "abstract" to be a little bit like typedef in C. I wonder why. Care to elaborate. But in answer to your actual question....

    You failed to post the entire snippet, but I suspect it looked like this

    ..new AbstractAction() {
    // stuff
    }Yeh sneakily, they've created an anonymous inner class that's a concrete subclass of AbstractAction

    DB:2.66:Re: A Question.... d7

    Now I got it :-) Thanks all! / Mats

  • RELEVANCY SCORE 2.66

    DB:2.66:Interface Abstract And Concrete Class d1


    Do i have the right in java to extend an abtract class to a concrete class and also to implement the ineface
    in the concrete class

    What am i saying is

    public class concrete extends abstract implements interface ??

    DB:2.66:Interface Abstract And Concrete Class d1

    That's what inheritance in Java is all about Yup, generally its a very logical and robust design model that is right at the heart of OOP. Extending an abstract defined class also involves (though not necessarily) 'encapsulation' as well as inheritance. An interface on the other hand is a means to define methods, ie: you create the conditions of what you want to do, with deferred implementations - in other words there are no { - to stuff here -} code blocks. Absract classes on the other hand may or may not have deferred methods and implemented methods inherited by the subclass or inheriting class are allowed.

    It's common convention to let class and interface
    names start with a capital letter.It is highly illogical to do anything otherwise.

  • RELEVANCY SCORE 2.66

    DB:2.66:Can't Use Subclass As Argument To Method. 9z


    Hi All,

    I'm probably being really stupid but I can't figure out the following:

    I have the following class superclass:

    public class Credentials
    {
    private String username;

    public String getUsername()
    {
    return username;
    }

    public void setUsername(String username)
    {
    this.username = username;
    }
    }And a class which subclasses it:

    public class ASADMINCredentials extends Credentials
    {
    private int domainAdminPort;
    private String instance;
    private String passwordFilePath;

    public ASADMINCredentials()
    {
    super();
    }
    //more getters and setters ommitted for brevity...I then have an interface which defines the superclass as an argument:

    public interface AppStateController
    {
    public boolean enableApplication(Credentials credentials, String application);

    public boolean disableApplication(Credentials credentials, String application);
    }And a concrete implementation class which implements the AppStateController interface, the implementation class passes in a subclass of Credentials:

    public class ASADMINAppStateController implements AppStateController
    {
    public boolean enableApplication(ASADMINCredentials credentials,
    String application)
    {
    //code ommitted for brevity...
    }

    public boolean disableApplication(ASADMINCredentials credentials,
    String application)
    {
    //code ommitted for brevity...
    }I thought it was valid to pass a subclass to a method in place of it's superclass but for some reason I get the following error:

    class ASADMINAppStateController must either be declared abstract or implement abstract method enableApplication(Credentials, String) in AppStateController

    I have also tried changing the interface to the following with the same result:

    public interface AppStateController
    {
    public K extends Credentials boolean enableApplication(K credentials, String application);

    public K extends Credentials boolean disableApplication(K credentials, String application);
    }Could some please explain to me what I'm doing wrong here? Is it because the Credentials and ASADMINCredential classes don't truly share the same interface in terms of public methods? I'm sure I've done this in the past and am feeling particularly stupid at the moment so would be grateulf for some enlightenment!

    Many thanks,

    Edd

    DB:2.66:Can't Use Subclass As Argument To Method. 9z

    And the reason your original code DIDN'T work is this:

    public class SomeNewKindOfCredential extends Credentials {...}

    AppStateController controller = factory.getASADMINAppStateController();
    controller.enableApplication(new SomeNewKindOfCredential());That is, if some piece of code was referencing your ASADMINAppStateController through its interface (and all code is, isn't it? Otherwise what's the point of the interface?) then the interface declaration allows you to pass any kind of Credentials. Hence, narrowing of parameter types is not permitted. Widening is. And narrowing of return types (co-variant return types) is permitted since Java 5 too.

  • RELEVANCY SCORE 2.66

    DB:2.66:Re: Abstract Factory Pattern fd


    Original Posters Request:
    My issue is that I would like all the concrete class
    to be added automatically (somehow) to thehashtable
    or have a method that gives my an overview of the
    available concrete classes so that a client can ask
    for them and then choose which one to pick. Is therea
    way to achieve thisDid you read any of the other repsonses?Yes I did, however I was addressing one of his original requests.

    Hence, all extending subclasses will gain the
    getFactory(String name) method,Isn't that what inheritance gives you?Yes but inheritance dosen't give you a direct invocation into the Aspect Class which actually calls back into the registerIfNecessary() method in the Abstract Factory class.

    which when invoked by
    the subclass will actually be calling the parent
    classes getFactory(String name) method.
    Which using
    aspectJ will then automatically add the subclass to
    the parent classes Hashtable, thus solving the OP's
    request.And how does the method get invoked?The Aspect invocation will get weaved into the KPIFactory.getFactory(String name) method which will call into the Aspect class that in turn calls back into the KPIFactory.registerIfNecessary().

    Have a look at the code i supplied in one of the earlier posts.

    Cheers
    Bones

    DB:2.66:Re: Abstract Factory Pattern fd

    If they are implemented this way then they are most
    like not Abstract Factories, this doesn't make them
    wrong, just not Abstract Factories. Though it seems
    to me you do not understand the distinction between an
    Abstract Factory and a Factory Method.No I understand quite well. Looking back at the OP I realize that you are correct, this is not an Abstract Factory. I really didn't look at it that closely. I thought you were saying that since it returned instances of the implementations it wasn't an Abstract Factory. I should pay closer attention.

  • RELEVANCY SCORE 2.66

    DB:2.66:Singleton Pattern And Abstract Class zz


    Hi:
    I want to implement singleton pattern with a twist:
    I want my object to be polymorphic, so I have a (super) abstract class. Now, I have a problem: I can't implement an abstract getInstance() method in the abstract class because an abstract method cannot be static. But I feel very unsatisfied implementing getInstance() only in the concrete class and gives no hint in the abstract class, giving no way to enforce that getInstance() has to be implemented in the concrete subclass.

    Does anyone have an idea how I get around this? Thanx!

    DB:2.66:Singleton Pattern And Abstract Class zz

    The point is, that someone has to instantiate the child class.
    This could for instance occur by reading a class name from an XML file,
    and do a class.forName.

    As you have a singleton, simply make a base class
    public class Base {
    private static Base instance = null;
    protected Base() {
    if (instance != null)
    throw new IllegalArgumentException();
    instance = this;
    }
    /**
    * @return instance, possibly null
    */
    public getInstance() {
    return instance;
    }
    }

  • RELEVANCY SCORE 2.65

    DB:2.65:Problem About This(...) And Super(...)! 71


    what I want to do is :

    class subclass extend superclass
    {
    public subclass()
    {
    Do Something here.....

    }
    public subclass (....)
    {
    super(....);
    this();
    }
    }

    how can I do it?

    DB:2.65:Problem About This(...) And Super(...)! 71

    Here's another one:
    class subclass extend superclass
    {
    public subclass()
    {
    this(....);
    }
    public subclass (....)
    {
    super(....);
    Do Something here.....
    }
    }

  • RELEVANCY SCORE 2.65

    DB:2.65:Re: What Is The Advantage To Have Constructor In Abstract Classes? c1


    ur explaination is good, However i have question about
    those Abstract class variables? where would they saved
    in memory? because there is no instance of that class?
    but we have only subclasses which called Abstract
    class constructor via super()? where would those
    variable will save in memory?The variables defined in the abstract class will be saved together with the variables of the concrete subclass in the instantiated object. It's the same as with a concrete (not abstract) superclass.

    DB:2.65:Re: What Is The Advantage To Have Constructor In Abstract Classes? c1

    I appreciated ur patient with me for clearing my
    doubts. thanks a lot for u. what is ur job? r u
    student or employee? which is ur place?
    my email is kneethan@hotmail.com, I'm selfemployed. I do contract jobs, write own applications (and play the stock market -:)

    Right now I'm coding on a Java program of my own program called Mint (molecular interactions). You use it to simulate the behaviour of large molecules (proteins, DNA). You can watch them in 3D and turn and twist them and at the same time a simulation is running so all atoms are moving in relation to each other.

    Good luck with Java.

  • RELEVANCY SCORE 2.65

    DB:2.65:Factory Pattern And Overriding 7j


    Hi all,

    I'm currently refactoring an application which uses two different libraries according to the user input.

    There is a Factory class who returns instances of, let's say, MetadataB and MetadataB, both subclass of Metadata.

    This is fine if the user calls one of the method exposed by the superclass Metadata, because under the hood it is the concrete implementation of the subclass that works.

    Now, I would like to add some methods to one class but not the other, and expose them to the user according to her initial choice.
    This breakes the previous pattern.
    Any solution for this refactoring? (can't ask the user to make an explicit casting)

    Thanks a lot

    DB:2.65:Factory Pattern And Overriding 7j

    Okay, let's start again from the beginning.

    Hi all,

    I'm currently refactoring an application which uses
    two different libraries according to the user input.When you say 'libraries', do you mean classes, packages or JAR files?

    There is a Factory class who returns instances of,
    let's say, MetadataB and MetadataB, both subclass of
    Metadata.No issues here. Though, I am assuming one is in fact MetaDataA and the other is MetaDataB.

    This is fine if the user calls one of the method
    exposed by the superclass Metadata, because under
    the hood it is the concrete implementation of the
    subclass that works.Inheritance and polymorphism.

    Now, I would like to add some methods to one class
    but not the other, and expose them to the user
    according to her initial choice.
    This breakes the previous pattern.
    Any solution for this refactoring? (can't ask the
    user to make an explicit casting)Again, take a look at the Decorator pattern. However, there are a number of terms in here causing me concern. How would you 'expose' certain methods to a user based on a choice? Further, how would a user ever initiate a run-time cast? What is the user actually doing?

    Thanks a lot- Saish