🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2330

Re: Ownership of objects

#2330
From: Read Fleming
Date: Fri, 27 Oct 1995 18:24
26 lines
1632 bytes
"Taligent's Guide to Designing Programs" (Addison Wesley, 1994) has
some things to say about this.  Taligent recommends a naming convention
for C++ functions that can be summarized as follows:

Create... for functions that make a new object that the caller must
  delete.

Copy... for functions that copy an existing object that the caller
  must delete.

Orphan... for functions that pass deletion responsibility to the caller.

Adopt... for functions that assume responsibility for deleting objects
  that have been allocated by the caller.

This convention can be extended for argument names; e.g., a constructor
for an objects that takes on ownership of the arguments:

  AndNode::AndNode(Node* adoptedLeftChild, Node* adoptedRightChild)

IMHO, object ownership is not a big deal if you conciously design for it,
and use conventions like those above to help document the decisions.
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <9510271247.AA00995@morthra.cadre.com>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 27 Oct 95 18:24:34 GMT
Approved: fjh@cs.mu.oz.au
Organization: -
Newsgroups: comp.std.c++
X-Original-Date: Fri, 27 Oct 1995 08:47:51 -0400
From: rtf@cadre.com (Read Fleming)
Message-ID: <9510271247.AA00995@morthra.cadre.com>
Subject: Re: Ownership of objects
Cc: rtf@cadre.com
X-Sun-Charset: US-ASCII
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMJEj7uEDnX0m9pzZAQGZrAGAg1XCL2FYqiVkL82TJNA7HMCi4Amc/Leg
 0azDV+JlYB8qRIX4YKglrCLrrGYWpu5T
 =jdR6