Go to Post Over Weight. What else is to be expected? There is still time for the diet team to perform miracles. Meanwhile I still keep adding parts. - Steve W [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-02-2009, 05:33
kim123 kim123 is offline
Registered User
None #0080
 
Join Date: Feb 2009
Location: california
Posts: 1
kim123 is an unknown quantity at this point
why encapsulation is required?

hi,

Please tell me why encapsulation is required?

Thanks
  #2   Spotlight this post!  
Unread 03-02-2009, 05:45
kiettyyyy's Avatar
kiettyyyy kiettyyyy is offline
Registered User
FRC #1538 (The Holy Cows)
Team Role: Engineer
 
Join Date: Mar 2006
Rookie Year: 2005
Location: San Diego, CA
Posts: 181
kiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond repute
Send a message via AIM to kiettyyyy
Re: why encapsulation is required?

Encapsulation in regard to????
__________________
-Kiet Chau

2004-2008 - Software Developer/Driver on Team #968
2008-2011 - Software Developer/Coach/Mentor/"Engineer" on Team #968
2011-Present - Mentor & Engineer on Team #1538
www.team1538.com
  #3   Spotlight this post!  
Unread 03-02-2009, 07:42
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: why encapsulation is required?

http://en.wikipedia.org/wiki/Encapsu...mputer_science)
  #4   Spotlight this post!  
Unread 03-02-2009, 07:44
Analog's Avatar
Analog Analog is offline
Registered User
AKA: Bob Most
FRC #2619 (The Charge)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Midland, Michigan
Posts: 53
Analog will become famous soon enoughAnalog will become famous soon enough
Re: why encapsulation is required?

Quote:
Originally Posted by kim123 View Post
hi,

Please tell me why encapsulation is required?

Thanks
Be more descriptive.
  #5   Spotlight this post!  
Unread 03-02-2009, 08:38
JamesBrown JamesBrown is offline
Back after 4 years off
FRC #5279
Team Role: Engineer
 
Join Date: Nov 2004
Rookie Year: 2005
Location: Lynchburg VA
Posts: 1,281
JamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond repute
Re: why encapsulation is required?

From Wikipedia:

Encapsulation is the hiding of information. C++ implements encapsulation by allowing all members of a class to be declared as either public, private, or protected. A public member of the class is accessible to any function. A private member is accessible only to functions that are members of that class and to functions and classes explicitly granted access permission by the class ("friends"). A protected member is accessible to members of classes that inherit from the class in addition to the class itself and any friends.

The OO principle is that all of the functions (and only the functions) that access the internal representation of a type should be encapsulated within the type definition. C++ supports this (via member functions and friend functions), but does not enforce it: the programmer can declare parts or all of the representation of a type to be public, and is allowed to make public entities that are not part of the representation of the type. Because of this, C++ supports not just OO programming, but other weaker decomposition paradigms, like modular programming.

It is generally considered good practice to make all data private or protected, and to make public only those functions that are part of a minimal interface for users of the class. This hides all the details of data implementation, allowing the designer to later fundamentally change the implementation without changing the interface in any way




In general whenever you are writing an API, or any interface for other people to use encapsulation is a good practice. without encapsulation teams would have to rewrite their code every time WPILib made changes to a function that they use. With encapsulation if the inputs and outputs to a function remain the same then WPILib can be changed without effecting teams.
__________________
I'm Back


5279 (2015-Present)
3594 (2011)
3280 (2010)
1665 (2009)
1350 (2008-2009)
1493 (2007-2008)
1568 (2005-2007)
  #6   Spotlight this post!  
Unread 03-02-2009, 09:02
pheadxdll pheadxdll is offline
Registered User
AKA: Alex
FRC #1225 (Amperage Robotics)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2006
Location: North Carolina
Posts: 168
pheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud of
Re: why encapsulation is required?

Quote:
Originally Posted by kim123 View Post
hi,

Please tell me why encapsulation is required?

Thanks

Recent practical example: C/C++ Team Update #3. Encapsulation allows updates to the WPILib without borking your program. It's a common coding practice in industry.
__________________
Amperage Robotics Team 1225
Site under-going revamp. :/

Last edited by pheadxdll : 03-02-2009 at 09:04.
  #7   Spotlight this post!  
Unread 03-02-2009, 09:28
Mageofdancingdr's Avatar
Mageofdancingdr Mageofdancingdr is offline
Mageofdancingdragons
AKA: DJ Hoffman
FRC #0599 (Robodox)
Team Role: Alumni
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Los Angeles
Posts: 24
Mageofdancingdr is an unknown quantity at this point
Re: why encapsulation is required?

FIRST is supposed to be a simulation of a real engineering experience. real engineers use encapsulation because it is more secure against malicious programmers and their programs. This is also why proper memory allocation is important as well. Keeping code secure from outside influence is important so that
A) the code doesn't interfere with other processes on the same machine
B) outside programmers can't access it
C) it allows for a more modular type of code where simple function calls change not entire blocks of code.
__________________
3.1415926535897932384626433832
  #8   Spotlight this post!  
Unread 03-02-2009, 10:06
galewind's Avatar
galewind galewind is offline
... more like a temperate breeze
AKA: Chris Gregory
FRC #1089 (Team Mercury)
Team Role: Teacher
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Hightstown, NJ
Posts: 410
galewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond repute
Send a message via AIM to galewind
Re: why encapsulation is required?

Here's an example of why encapsulation is important.

Let us, for a moment, assume that you have variables within an object that are directly related to other variables within that same object. Thus, changing one requires that you adjust others in order to compensate for the change. The object itself should ultimately be responsible for updating itself to make sure that the data correlates accordingly.

Simple example: Assume we made a Rectangle class that contained four variables - length, width, area, perimeter. Please note that area and perimeter are derived from length and width (normally I wouldn't make variables for them), so that changing length would change both area and perimeter.

If you did not use proper information hiding (encapsulation), then another program utilizing that Rectangle class could alter the length without altering the area, and you would have an inconsistent Rectangle. Without encapsulation, it would be possible to create a Rectangle with a length of 1 and a width of 3, and have an area of 32345.

Using encapsulation, we can create a function that, if a program wanted to change the length of the rectangle, that the object would appropriately update its area and perimeter without being inconsistent.

Encapsulation eliminates the possibilities for inconsistency, and shifts the responsibility of staying consistent onto the object itself rather than a program utilizing it.
__________________
Chris G
Advisor, Team Mercury (1089), Hightstown High School

Last edited by galewind : 03-02-2009 at 10:10. Reason: clarifications
  #9   Spotlight this post!  
Unread 05-02-2009, 00:26
virtuald's Avatar
virtuald virtuald is online now
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,086
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: why encapsulation is required?

Quote:
Originally Posted by Mageofdancingdr View Post
Real engineers use encapsulation because it is more secure against malicious programmers and their programs.
No, definitely not. You *could* make a statement that it makes things easier to debug, and thus more secure, but even then that is not strictly true.

Quote:
This is also why proper memory allocation is important as well. Keeping code secure from outside influence is important so that
A) the code doesn't interfere with other processes on the same machine
B) outside programmers can't access it
While proper memory allocation is a good thing, these are totally different issues. This is a *type* of encapsulation, but it certainly isn't the encapsulation one talks about when talking about programming languages (and really, (B) isn't even true in many situations that we won't go into here... ).

As someone above has pointed out, WPILib is a great example of why encapsulation is a good thing. Clearly it does not contribute to the security of the program.

For example, just because you declare something in a class as 'private' does not mean someone cannot access it (in absolute terms). Generally, accessing private members in a class will not compile correctly -- however if you had a raw pointer to the member then you could easily change the item, despite it being private. Additionally, there are a few ways one could make something that accesses a private member compile if you wanted to be truly nasty: see http://www.gotw.ca/gotw/076.htm if you're interested.

Quote:
C) it allows for a more modular type of code where simple function calls change not entire blocks of code.
This is the correct answer (though its more generic than just simple function calls).
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
volunteers required? excel2474 District Events 8 29-03-2009 20:00
Required documentation Japper General Forum 2 11-03-2008 10:40
Batteries Required?? thinkpad Electrical 28 19-04-2005 05:59
Varification Required Mark Reynolds Programming 1 31-01-2004 17:01


All times are GMT -5. The time now is 21:50.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi