Skip to main content

Object & Container Object

Object / Class


What is Object? Object can be people, can be animal, can be anything.
  • Object only store his own data, attributes and property like house has price, size and animal has age and gender. 
  • Object also store his own function or method like animal can eat(); and people can walk();.
Try imagine an object is a people, what should it have and what should it don't have? Let's take this example.


public class People
{
    private: 
        String name;
        int age;
        int hungry;
    public:
        void grow()
        {
            this->age += 1;
        }

        void eat()
        {
            hungry = false;

        } 
}

People can eat, people will grow up so this is true but you try imagine a people can fly(); ? What other programmer see when want to use ur code?

"WTF, WTF is this? Oh my godness."

so just store whatever the object need, have is enough. When some attribute is too much and enable to split to another object, you can also split it like Customer have many Orders and Orders have many attribute so you can make it become 2 object like the example below:

class Customer
{
	private:
		String name;
		Order orders[10];
}

class Order
{
	private:
		String product;
		double price;
		int quantity;
}

Container Object

Take container as another example, how we add object to a container? We can't put add(); inside people object. Remember everything is an object, container also an object. If a container have a add(); doesn't have any problem, and it will be like "Object has a object" and "Container contains a people". Here an example :
 
People people = new People();
Container container = new Container();

container.add(people);
As you see, container inside contains people but people cant inherit to container they are relation about storing but not inherit. Container can't access people's data, attribute, method, functions and only can add, remove, get, delete. Container also look like a manager managing list of people object.


Always remember everything are object and we treat everything as object. Object can be everything can be container, object, manager or many that structure you can think and make your structure better.

Popular posts from this blog

Backend Developer & Development [ Part 1 ]

Backend developer is a develop who maintain the work users /  clients can't see such as processing transaction, data structure, data transfer. These works would contains in a API server and API server contains many endpoint that can call by anyone but only success when fulfill endpoint requirements so it is secured. API Server also know as REST API ( Representational State Transfer ). It's processing like client request to server & after server process return response to client. API Server is develop by backend developer and this api server can be many type and different language, different framework such as Ruby on Rails ( RoR ) using Ruby Python PHP ( Laravel & Yii2 ) Java ( Spring ) C# ( ASP.NET & NancyFX ) Node.JS ( ExpressJS, SailsJS, HapiJS, NestJS, FeatherJS ) Different framework have their own advantages and can be used on different projects based on their features and usage. In the development not only choosing frameworks also need to ch...

Local Development | LAN [ Local Area Network ]

Before an application, website, backend server, frontend app or any application required to integrate with another platform, how you work with your friends? Put all in one computer for testing?  Upload to a free hosting for testing like Heroku ? If your team able to work in same place, i would suggest hosted own local network for testing at least faster then using other free platform like Heroku. As of improvement of technology, nowadays network interface card ( NIC ) would have a feature about HostedNetwork. You can host your local area network ( LAN ) for your friends and they can access your works and testing at their own computer and fix would faster the development. In Windows You can use command prompt and type "netsh wlan show drivers" and check is "Hosted network supported : ". If supported you can create your local area network by using command "netsh wlan set hostednetwork mode= allow ssid= YourAP key= YourPW ". YourAP  = Acc...

Coming back to MinecraftAPI

A long time for stop developing minecraft plugins due to busy about university and side works. Coming back from a long learning journey, i decide to recode my personal minecraft api for upcoming new server. Found that the code now i can build it with more structural design pattern. Such as MinecraftAPI interface class for runtime reloadable content. package me.oska.core.abs; public interface MinecraftAPI { void register(); void unregister(); void intialise(); void teardown(); } Also i have updated my reader utility code for reading jar class with functional interface make it more flexible. package me.oska.core.util; import me.oska.core.OskaCore; import me.oska.core.lambda.VoidAction; import org.apache.commons.io.FilenameUtils; import java.io.File; import java.net.URL; import java.net.URLClassLoader; import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile; public class ReaderUtil { public static void readJAR(File fold...