Book a Demo

Author Topic: Inherit from EA classes  (Read 3718 times)

JoB

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Inherit from EA classes
« on: February 26, 2010, 10:24:46 pm »
Why is it that all classes in the automation interface have internal constructors? This means that I cant't derive from them in my Add-In and build my own, much better organized ;), EA classes. Is there any good reason why Sparx have made this design decision?

Is there any way around this? So that I can derive from e.g. PacketClass.

[edit]I can indeed use extension methods to achieve what I want.

Code: [Select]
static class PackageExtensions
    {
        public static Package GetSubPackageByName(this Package package, string name)
        {
            Package subPackage = package.RecursiveFindSubPackageByName(name);
            if (subPackage == null)
                throw new ArgumentException(String.Format("There is no sub package with name {0}", name));
            return subPackage;
        }

        private static Package RecursiveFindSubPackageByName(this Package package, string name)
        {
            Package recursiveSubPackage = null;
            foreach (Package subPackage in package.Packages)
            {
                if (package.Name == name)
                    return subPackage;
                recursiveSubPackage = subPackage.RecursiveFindSubPackageByName(name);
                if (recursiveSubPackage != null) return recursiveSubPackage;
            }
            return null;
        }
}
[/edit]
« Last Edit: February 26, 2010, 10:50:28 pm by JoB »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Inherit from EA classes
« Reply #1 on: February 26, 2010, 10:49:59 pm »
JoB,

Please see http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1267179584 for my view on this subject.

Geert
« Last Edit: February 26, 2010, 10:50:19 pm by Geert.Bellekens »

JoB

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Inherit from EA classes
« Reply #2 on: February 26, 2010, 10:53:51 pm »
I can't see what that has to do with the subject. Are you sure it was the thread How to make an element Composite via API you meant?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Inherit from EA classes
« Reply #3 on: February 26, 2010, 10:57:43 pm »
No, i missed.  :-[
I meant to point to this one: http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1267114762 (last reply)

Geert