Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Passing extended object information...

Posted on 2006-05-08
Medium Priority
Last Modified: 2010-04-16
If i have an object and then another object that extends that original object...
and I want to pass an object i already have loaded and set with information to a new extended version of that object....
what would be the easiest way for me me to do that?  
Here's what i'm doing now....

public static main()
   BaseObject b1 = new BaseObject("MyObject");
   ExtendedObject e1 = new ExtendedObject( b1 );

class BaseObject
  private string Name = "";
  public string Field1 = "";
  public string Field2 = "";
  public string Field3 = "";
  public string Field4 = "";
  public string Field5 = "";
  public baseObject (string strName)
    this.Name = strName;

class ExtendedObject : BaseObject
  public extendedObject( baseObject baseobj )
    this.Name = baseobj.Name;
    this.Field1 = baseobj.Field1;
    //etc.. you get the point.

Question by:collages
  • 2
LVL 12

Expert Comment

ID: 16632757

 What you tried to do with a constructor for ExtendedObject that takes a parameter of BaseObject type is achieved with
    BaseObject b1 = new BaseObject("MyObject");
    ExtendedObject e1 = b1;
  you don't need that type of constructor.

Instead, you may have a constructor for ExtendedObject that calls the base class constructor with the same parameters like

  public extendedObject(string strName) : base(strName)
    // you get the point ...

LVL 12

Accepted Solution

sumix earned 2000 total points
ID: 16636575

Sorry collages, I gave you a wrong answer!
you cannot have an implicit conversion like
  ExtendedObject e1 = b1;
 only backwards...

Even though you may have a constructor like the one I indicated, for what you try to do, your solution (constructor that takes a parameter of base class) is a good one.


Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question