Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8362665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:59:36+00:00 2026-06-09T11:59:36+00:00

Create an instance from another one of different kind/class. Quick example: you are using

  • 0

Create an instance from another one of different kind/class.

Quick example: you are using an ORM and you store an email queue in your database. Then at some point you have to send bulk emails, using third party library.

Your object (PHP irrelevant here, public properties for simplicity):

class Mail
{
    /**
     * @var string
     */
    public $senderText;

    /**
     * @var My\App\Entity\User
     */
    public $user;

    /**
     * @var \Doctrine\ORM\ArrayCollection
     */
    public $attachments;
}

… while your third party “mail” object is far different. For example, you may need to do something like:

$mail = /* hydrated */;
$user = $mail->getUser();

$mailer = new ThirdPartyMailer();

// Fill message properties
$message = $mailer->createMessage();

$fullName = sprintf('%s %s', $user->getFirst(), $user->getLast());
$message->addFrom(array($fullName => $user->getEmail()))

// Create and add attachments
foreach($mail->getAttachments() as $attachment)
{
    $message->attach($mailer->createAttachment($attachment->getFullPath()));
}

Is this a pattern? Something like object converter, like a class responsible of creating/converting one instance from another…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:59:37+00:00Added an answer on June 9, 2026 at 11:59 am

    I’m not aware of a single widely used name for this pattern, but some common names are “translator” and “converter” — a class that translates between two different classes representing similar entities.

    A related pattern is the adapter pattern: if the third-party message is exposed as an interface, you could create an adapter class that wraps your existing mail object and implements the third-party interface.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

to create an instance of another class from a class even if the class
How does one create a java.security.cert.X509Certificate instance from a PEM-formatted String? The PEM-formatted String
What would be correct way to create new instance of the class from class
I have a class that desccends from ListviewItem. When I create an instance of
I am trying to create an AMI from an instance store instance on amazon
Example: I have an class that inherits from UIImageView. An object creates an instance
I am transferring a message from one emulator instance on a machine to another
I moved my PostgresQL database from one hard drive to another using pg_dump -U
I'd like to create another app from my main app, for instace 'app with
What is the best way to create instance of CCSprite from downloaded image file?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.