100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Computer Science 144 3.2 summary R70,00   Add to cart

Summary

Computer Science 144 3.2 summary

 32 views  0 purchase

Detailed summary of chapter 3.2 - creating data types in Python. Includes everything you need to know about chapter 3.2 for the A1

Preview 1 out of 4  pages

  • No
  • Unknown
  • September 28, 2023
  • 4
  • 2023/2024
  • Summary
book image

Book Title:

Author(s):

  • Edition:
  • ISBN:
  • Edition:
All documents for this subject (4)
avatar-seller
jaidendutoit
3.2 CREATING DATA TYPES

Introduction:
Data abstraction = the process of defining a data type
Another mantra: whenever you can clearly separate data and associated operations within
computation, you should do so

Basic elements of a data type:
API:
The application programming interface is the contract with all clients and, therefore, the
starting point for any implementation.
When creating a new data type for some application, the first step is to develop an API = a
design activity.
It is a good idea to compose some client code before finalizing the API.
Second step to creating a data type -> implement a Python class that meets the API
specifications.
Third step: compose a test client, to validate and test the design decisions made in the first
two steps.
Purpose of API: to separate clients from implementation.

Class:
We implement a data type as a class and name it with the same name as the class but with a
lowercase and followed by the .py extension.
3 key features of a data type (all different types of methods):
- A constructor
- Instance variables
- Methods


Constructor:
-> creates an objects of the specified type and returns a reference to that object.
Each data type defines a special method __init__() whose purpose is to define and initialise
the instance variables.
The first parameter in the constructor(__init__() method) is named self, followed by ordinary
parameter variables; the remaining lines make up the body of the constructor. The value of
the self parameter variable when __init()__ is invoked is a reference to the newly created
object

Instance variables:
-> implement the values and belong to a
particular instance of a class
Define and initialise each instance variable of the
newly created object in the constructor.
Instance variables start with an underscore.

Methods:

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through EFT, credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying this summary from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller jaidendutoit. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy this summary for R70,00. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

79223 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy summaries for 14 years now

Start selling
R70,00
  • (0)
  Buy now