Objects in code

Everything I read about object oriented code gives an example, like an animal, that has features such as a number of legs, and a breed, and any number of other, entirely-irrelevant-to-real-life-examples. These examples are good at describing the very, very high-level concept, but they fail to provide the concrete examples that a user might genuinely need in their coding life.

A module I have written pulls data from Active Directory, and has functions that can change that data. I believe this is a much clearer example than one that uses imaginary animals.

public class AD
     public static string domain;

     public AD(DirectoryEntry de)
          DirectoryEntryI = de;
          //Other methods

     private DirectoryEntry _DirEntry {get;set;}
     public DirectoryEntry DirEntry
               if (this.DN is string objectDn)
                    _DirEntry = new DirectoryEntry("LDAP://" + objectDn);
                    return _DirEntry;
               return null;

This class contains a constructor, uses Microsoft APIs [it would need “using System.DirectoryServices” above the namespace declaration], has member variables [DirEntry and _DirEntry] which have different accessibility, has a function [UpdateDN() which I have not included in the code to make it easier to read] and has a non-member variable to store the domain of this Active Directory object.

Personally, I think this is a far more interesting example.

About the author

Code and Copy is a career, travel and general information website written by Gavin Ayling.
Gavin is a copywriter, software coder, and board gamer living in beautiful New Hampshire. He has been blogging since 2002 and has been a celiac since the early 1980s.
Gavin has traveled to over 40 countries and has lived in three countries on different continents.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

WP Twitter Auto Publish Powered By : XYZScripts.com