Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

A class extends another but imports the same libraries

Participant ,
Apr 15, 2013 Apr 15, 2013

These are imported by the parent class and the child class

import com.Gerry.db.DbManager;

import com.Gerry.controller.Home;

import com.Gerry.data.Data;

One of my classes extends another but both import the same libraries. (I inherited this code). That doesn't make sense does it. By extending a class you inherit all the libraries etc... right?

TOPICS
ActionScript
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 15, 2013 Apr 15, 2013

it makes sense.

class files need to import all the classes used in their scope.

Translate
Community Expert ,
Apr 15, 2013 Apr 15, 2013

it makes sense.

class files need to import all the classes used in their scope.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 16, 2013 Apr 16, 2013

There is no yes/no answer to this. As kglad said, classes that have references to their datatypes in the current instance must be imported. Nevertheless, if there is no reference to datatypes but just variables - there is no need to import.

Here is an example (see code below). SubClass extends SuperClass. The code demonstrates that:

1. Although SubClass is Sprite - you don't need to import Sprite BUT you can use any Sprite API.

2. Variable movieClip is inherited by SubClass. Although you can use all MovieClip related API - there is no need to import MovieClip class in SubClass.

3. Because TextField is instantiated as distinct vars in both SuperClass and SubClass - TextField must be imported in both.

package 

{

          import flash.display.MovieClip;

          import flash.display.Sprite;

          import flash.text.TextField;

          public class SuperClass extends Sprite

          {

                    public var movieClip:MovieClip;

                    public var superText:TextField;

                    public function SuperClass()

                    {

                              movieClip = new MovieClip();

                    }

 

          }

}

package 

{

          import flash.text.TextField;

          public class SubClass extends SuperClass

          {

                    public var subText:TextField;

                    public function SubClass()

                    {

                              super();

                              addChild(movieClip);

                              movieClip.play();

                    }

 

          }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 16, 2013 Apr 16, 2013

Well just to get some more clarification here:

1. You say I can access variables as you have used the super() keyword BUT surely only those declared in the parent/super class constructor.

     I wouldn't be able to access variables declared out of the scope of the constructor ie: in other functions within that class???

2. Variables YES but methods or functions NO. Is that right? ie: To get access to a Classes methods/functions I would have to instantiate it - is that right?

Cheers - this is great learning as all OOP stems from this. I understand more and more every day looking at the basics. I suppose all complex apps are made up of hundreds of simple functions.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 16, 2013 Apr 16, 2013

1. Disregard super() call for now - it is called automatically by subclass.

2. Subclass can access any variables that are declared (even if they are not instantiated) in the scope of the super class as public or protected. Constructor has nothing to do with it.

3. Subclass can access any public and protected methods of super class - similar to properties. As a matter of fact you should try (no matter how counterintuitive it sounds) to mentally blur distinction between methods and properties - they are all just one thing - objects.

I am not sure I actually understood your latest post completely... Need a bit of paella to replenish brain fuel.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 16, 2013 Apr 16, 2013

I see you are well versed in the ways of the coder. I bow before your master classes.

Thank you again.

G

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 16, 2013 Apr 16, 2013

Hehe.

Now I want a dumpling instead of paella unless, of course, it wasn't oriental but rather Star Wars theme in which case I revert to the former.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 16, 2013 Apr 16, 2013

By the way, while walking my dog I all of a sudden realized that I don't remember what they ate in Start Wars... Do you know anything about their gastronomy? I guess Yodas taste like alligator...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 16, 2013 Apr 16, 2013
LATEST

I was gonna mix up your last post to something like - I was eating my dog when suddenly I met Yoda - then I thought no...

All this code in such short time - Brain Freeeeeze!!!   No actually I am having fun because it's starting to make sense. In Summer I get 2 months holiday so will get right into it.

btw - you could get a virtual dog and get a pixeled virtual man to walk it. I could code it for you but then I will ask you 100 questions to ask you how to best design it. We could use a Singleton to hold his health, age, hunger etc... and implement interfaces on how he eats etc...

omg - I'll get serious in future posts with humour trickling in now and then to break up the monotony of coding on my own on a computer at 5:00 in the morning.

Cheers

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines